home *** CD-ROM | disk | FTP | other *** search
/ Action Games (2008) / akcnihry1.iso / GL Force 2001 3.0 / 3DFontView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-08  |  102.1 KB  |  4,158 lines

  1. /*
  2. Authors: David Nishimoto 
  3. Website: http://www.listensoftware.com
  4. Program: Force
  5. Email: davepamn@relia.net
  6. */
  7.  
  8. #include "stdafx.h"
  9. #include "MainFrm.h"
  10. #include "3DFont.h"
  11.  
  12. #include "3DFontDoc.h"
  13. #include "3DFontView.h"
  14. #include "help.h"
  15.  
  16. #include <time.h>
  17. #include <math.h>
  18. #include <MMSYSTEM.H>
  19.  
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. BOOL gameOver=FALSE;
  27. BOOL pause=FALSE;
  28. #define PI 3.142
  29. #define TRUE 1
  30. #define FALSE 0
  31. #define glRGB(x, y, z)    glColor3ub((GLubyte)x, (GLubyte)y, (GLubyte)z)
  32. #define GRID_SIZE 300
  33. #define dRadToDeg(x) (((float)x)*57.29577951308f)
  34. #define EXPLOSION_SIZE 50
  35. #define NUMBER_OF_MISSILES 50
  36. #define ASTEROID_COUNT 40
  37. #define BONUS_TYPE 1
  38. #define OBJECT_LIST_SIZE 40
  39. #define MINE_LIST_SIZE 10
  40. #define RIGHT_DIRECTION 1
  41. #define LEFT_DIRECTION 2
  42. #define FORWARD_DIRECTION 3
  43. #define LEFT 1
  44. #define RIGHT 2
  45. #define CENTER 3
  46. #define TORUS_TYPE 1
  47. #define SPHERE_TYPE 2
  48.  
  49.  
  50. typedef struct Engine{
  51.     GLfloat x,y,z;
  52.     GLfloat m_displacement;
  53.     long m_time_out;
  54.     GLint angle;
  55.     GLfloat m_angle_radians;
  56.     long m_cpu_clicks;
  57.     clock_t m_movement_interval;
  58.     long m_hit;
  59.     BOOL m_sleep;
  60.     GLint mTurretAngle;
  61.     BOOL mActiveFlag;
  62. }Engine;
  63.  
  64. Engine EnemyEngine[1];
  65.  
  66.  
  67. typedef struct OBJECT_STRUCT{
  68.     GLint m_id;
  69.     GLfloat m_x;
  70.     GLfloat m_y;
  71.     GLfloat m_z;
  72.     GLfloat m_t;
  73.     GLfloat m_Vox;
  74.     GLfloat m_Voy;
  75.     GLfloat m_Vo;
  76.     GLfloat m_Xo;
  77.     GLfloat m_Yo;
  78.     GLint m_value;
  79.     GLint m_hit;
  80.     GLint m_direction;
  81.     GLfloat m_angle_radians;
  82.     BOOL m_available_flag;
  83.     BOOL m_active_flag;
  84. } OBJECT_STRUCT_TYPE;
  85.  
  86. OBJECT_STRUCT_TYPE shipMissile[NUMBER_OF_MISSILES];
  87. OBJECT_STRUCT_TYPE enemyMissile[NUMBER_OF_MISSILES];
  88. OBJECT_STRUCT_TYPE objBonusList[OBJECT_LIST_SIZE];
  89. OBJECT_STRUCT_TYPE objMineList[MINE_LIST_SIZE];
  90.  
  91.  
  92.  
  93. typedef struct Asteroid{
  94.     GLfloat m_angle_radians;
  95.     GLfloat m_x;
  96.     GLfloat m_y;
  97.     GLfloat m_z;
  98.     GLfloat dir_x;
  99.     GLfloat dir_y;
  100.     GLfloat dir_z;
  101.     GLfloat m_mass;
  102.     GLfloat m_velocity;
  103.     GLfloat m_size;
  104.     GLfloat m_radius;
  105.     GLint m_colorIndex;
  106.     long m_movement_interval;
  107.     GLint m_activeFlag;
  108. }Asteroid;
  109.  
  110. Asteroid objAsteroid[ASTEROID_COUNT];
  111.  
  112. typedef struct Force{
  113.     GLfloat m_angle_radians;
  114.     GLfloat m_xPos;
  115.     GLfloat m_yPos;
  116.     GLfloat m_zPos;
  117.     GLfloat m_delta;
  118.     GLint m_score;
  119.     GLint m_shield;
  120.     GLint m_hit;
  121.     int m_swing;
  122. }Force;
  123.  
  124. Force objForce;
  125.  
  126. typedef double MATRIX4X4 [4][4];
  127. typedef double MATRIX4X1 [4][1];
  128. typedef double MATRIX1X4 [1][4];
  129.  
  130. typedef struct VECTOR_STRUCT
  131. {
  132.     GLfloat m_x;
  133.     GLfloat m_y;
  134.     GLfloat m_z;
  135. } VECTOR_STRUCT_TYPE;
  136.  
  137. typedef struct explosion{
  138.     GLfloat x;
  139.     GLfloat y;
  140.     GLfloat z;
  141.     GLfloat scale_x;
  142.     GLfloat scale_y;
  143.     GLfloat scale_z;
  144.     long m_cpu_seconds;
  145.     long m_shield;
  146.     BOOL m_available_flag;
  147.     BOOL m_active_flag;
  148.     GLint type;
  149. }EXPLOSION_TYPE;
  150.  
  151. EXPLOSION_TYPE objExplosion[EXPLOSION_SIZE];
  152.  
  153. int vMap[10][10];
  154. int mLives=3;
  155.  
  156. long ellaspedTimeOut(Engine *objEngine);
  157. void setTimeOut(Engine *objEngine);
  158. void cone(GLfloat radius,GLfloat height);
  159. void cylinder(GLfloat radius,GLfloat height);
  160. void box(GLfloat w,GLfloat h,GLfloat d);
  161. void brassMaterial();
  162. void goldMaterial();
  163. void bronzeMaterial();
  164. void chromeMaterial();
  165. void copperMaterial();
  166. void silverMaterial();
  167. void pewterMaterial();
  168. void blackPlasticMaterial();
  169. void setDiffuseMaterialColor(GLfloat red, GLfloat green, GLfloat blue,GLfloat alpha);
  170. void setAmbientMaterialColor(GLfloat red, GLfloat green, GLfloat blue,GLfloat alpha);
  171. void setSpecularMaterialColor(GLfloat red, GLfloat green, GLfloat blue,GLfloat alpha);
  172. void setMaterialShininess(GLfloat shininess);
  173. void sphere(GLfloat radius);
  174.  
  175. double Matrix4X1_1X4(MATRIX4X1 *matrix1, MATRIX1X4 *matrix2);
  176. void Matrix4X1_4X4(MATRIX4X1 *result, MATRIX4X1 *matrix1, MATRIX4X4 *matrix2);
  177. void Matrix1X4_4X4(MATRIX1X4 *result, MATRIX1X4 *matrix1, MATRIX4X4 *matrix2);
  178. VECTOR_STRUCT_TYPE* rotate(GLfloat angle,GLfloat ux,GLfloat uy,GLfloat uz, VECTOR_STRUCT_TYPE *vector);
  179.  
  180. void calcNormal(GLfloat v[3][3], GLfloat out[3]);
  181. void calcNormal2(VECTOR_STRUCT_TYPE *vertex1, VECTOR_STRUCT_TYPE *vertex2,VECTOR_STRUCT_TYPE *vertex3,GLfloat out[3]);
  182. void reduceToUnit(GLfloat vector[3]);
  183. void torus(GLfloat innerRadius,    GLfloat outerRadius);
  184.  
  185.  
  186. void generateAsteroid();
  187. void force();
  188. void fireForceBall(GLfloat Yaw,GLfloat Pitch,GLfloat Vo);
  189. int checkAsteroidHit(GLfloat x,GLfloat y,GLfloat z);
  190. void drawTieFighter();
  191. void drawForceAsteroids();
  192. void drawForceMissiles();
  193. void empty();
  194. void tetrahedron();
  195. void icosahedron();
  196. int getAvailableMissile();
  197. void collision(int index1, int index2);
  198. int checkAsteroidCollision(int exclude_index,GLfloat asteroid1_x,GLfloat asteroid1_y,GLfloat asteroid1_z,GLfloat asteroid1_radius);
  199. void hyperboloid();
  200. void checkBonusCollision();
  201.  
  202. void drawEnemyWindshield();
  203. void drawEnemyBody();
  204. void Enemy();
  205. void Enemy_engine();
  206. void drawEnemy();
  207. void tieFighter();
  208. void drawExplosion();
  209. void moveEnemy();
  210. void moveEnemyEngine(int direction);
  211. int getAvailableEnemyMissile();
  212. void fireEnemyMissile();
  213. void drawEnemyMissiles();
  214. int checkShipHit(GLfloat x,GLfloat y,GLfloat z);
  215. int checkEnemyHit(GLfloat x,GLfloat y,GLfloat z);
  216. void toroidal_spiral();
  217.  
  218. void drawMine();
  219. void generateMines();
  220. int getMineObject();
  221. int checkMineHit(GLfloat x,GLfloat y, GLfloat z);
  222. void point_sphere(GLfloat radius);
  223. void checkEnemyCollision();
  224.  
  225. /////////////////////////////////////////////////////////////////////////////
  226. // CMy3DFontView
  227.  
  228. IMPLEMENT_DYNCREATE(CMy3DFontView, CView)
  229.  
  230. BEGIN_MESSAGE_MAP(CMy3DFontView, CView)
  231.     //{{AFX_MSG_MAP(CMy3DFontView)
  232.     ON_WM_CREATE()
  233.     ON_WM_DESTROY()
  234.     ON_WM_SIZE()
  235.     ON_WM_TIMER()
  236.     ON_WM_KEYDOWN()
  237.     ON_COMMAND(ID_FILE_PAUSE, OnFilePause)
  238.     ON_COMMAND(ID_FILE_NEW, OnFileNew)
  239.     ON_COMMAND(ID_FILE_RESUME, OnFileResume)
  240.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  241.     //}}AFX_MSG_MAP
  242.     // Standard printing commands
  243. END_MESSAGE_MAP()
  244.  
  245. /////////////////////////////////////////////////////////////////////////////
  246. // CMy3DFontView construction/destruction
  247.  
  248. CMy3DFontView::CMy3DFontView()
  249. {
  250.     int i;
  251.  
  252.     // TODO: add construction code here
  253.     srand( (unsigned)time(NULL) );
  254.     startGame();
  255.     buildSceneGraph();
  256.  
  257.     objForce.m_angle_radians=0.0f;
  258.     objForce.m_delta=0.0f;
  259.     objForce.m_xPos=-50.0f;
  260.     objForce.m_yPos=0.0f;
  261.     objForce.m_zPos=-20.0f;
  262.     objForce.m_score=0;
  263.     objForce.m_shield=100;
  264.     objForce.m_hit=0;
  265.     objForce.m_swing=CENTER;
  266.  
  267.     for(i=0; i<NUMBER_OF_MISSILES; i++)
  268.     {
  269.         shipMissile[i].m_available_flag=TRUE;
  270.         shipMissile[i].m_active_flag=FALSE;
  271.         enemyMissile[i].m_available_flag=TRUE;
  272.         enemyMissile[i].m_active_flag=FALSE;
  273.     }
  274.     for(i=0; i<ASTEROID_COUNT;i++)
  275.     {
  276.         objAsteroid[i].m_activeFlag=FALSE;        
  277.     }
  278.  
  279.     for (i=0; i<MINE_LIST_SIZE; i++)
  280.     {
  281.         objMineList[i].m_available_flag=TRUE;
  282.         objMineList[i].m_active_flag=FALSE;
  283.     }
  284.  
  285.     for (i=0; i<OBJECT_LIST_SIZE; i++)
  286.     {
  287.         objBonusList[i].m_available_flag=TRUE;
  288.         objBonusList[i].m_active_flag=FALSE;
  289.     }
  290.  
  291.     bonus_configuration();
  292.  
  293.     for(i=0; i<EXPLOSION_SIZE; i++)
  294.     {
  295.         objExplosion[i].x=0.0f;
  296.         objExplosion[i].y=0.0f;
  297.         objExplosion[i].z=0.0f;
  298.         objExplosion[i].scale_x=2.0f;
  299.         objExplosion[i].scale_y=2.0f;
  300.         objExplosion[i].scale_z=2.0f;
  301.         objExplosion[i].m_cpu_seconds=0;
  302.         objExplosion[i].m_available_flag=TRUE;
  303.         objExplosion[i].m_active_flag=FALSE;
  304.     }
  305.  
  306.     EnemyEngine[0].x=0.0f;
  307.     EnemyEngine[0].y=0.0f;
  308.     EnemyEngine[0].z=-50.0f;
  309.     EnemyEngine[0].m_displacement=1.0f;
  310.     EnemyEngine[0].m_angle_radians=1.57f;
  311.     EnemyEngine[0].m_sleep=FALSE;
  312.  
  313.     //PlaySound ("bluecoll.wav", NULL, SND_FILENAME | SND_ASYNC |SND_LOOP) ;
  314.  
  315. }
  316.  
  317. CMy3DFontView::~CMy3DFontView()
  318. {
  319.  
  320.     //PlaySound("", NULL, SND_PURGE | SND_NODEFAULT);
  321.  
  322.     cleanSceneGraph(root);
  323.  
  324. }
  325. BOOL CMy3DFontView::PreCreateWindow(CREATESTRUCT& cs)
  326. {
  327.     // TODO: Modify the Window class or styles here by modifying
  328.     //  the CREATESTRUCT cs
  329.  
  330.     return CView::PreCreateWindow(cs);
  331. }
  332.  
  333. /////////////////////////////////////////////////////////////////////////////
  334. // CMy3DFontView drawing
  335.  
  336. void CMy3DFontView::OnDraw(CDC* pDC)
  337. {
  338.     CMy3DFontDoc* pDoc = GetDocument();
  339.     ASSERT_VALID(pDoc);
  340.  
  341.     // TODO: add draw code for native data here
  342.     CPalette* oldPalette;
  343.  
  344.     //Set logic palette
  345.     oldPalette = m_pDC->SelectPalette(&m_Palette, FALSE);
  346.     m_pDC->RealizePalette();
  347.     
  348.     wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);
  349.     //DrawGLFont();
  350.     drawWithOpenGL();
  351.     SwapBuffers(m_pDC->GetSafeHdc());
  352.     wglMakeCurrent(m_pDC->GetSafeHdc(), NULL);
  353.     m_pDC->SelectPalette(oldPalette, FALSE);
  354. }
  355. void CMy3DFontView::drawWithOpenGL()
  356. {
  357.     CMainFrame* pFrame; 
  358.     char scorePhrase[200];
  359.     static GLfloat swing_angle=0.0f;
  360.     GLfloat swing_displacement;
  361.  
  362.     glShadeModel(GL_SMOOTH);
  363.     glEnable(GL_DEPTH_TEST);
  364.     
  365.     //clear color buffer
  366.     glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  367.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  368.     
  369.     //set light model
  370.     setLighting();
  371.     setBlending();
  372.  
  373.     glMatrixMode(GL_MODELVIEW);
  374.     glLoadIdentity();
  375.  
  376.  
  377.     if(objForce.m_swing==LEFT)
  378.     {
  379.         if (swing_angle>-0.9f)
  380.             swing_angle-= 0.1f;
  381.     }
  382.     else if(objForce.m_swing==RIGHT)
  383.     {
  384.         if(swing_angle<0.9f)
  385.             swing_angle+=0.1f;
  386.     }
  387.     else
  388.     {
  389.         if (swing_angle<-0.1f)
  390.             swing_angle+= 0.1f;
  391.         else if(swing_angle>0.1f)
  392.             swing_angle-= 0.1f;
  393.         else
  394.             swing_angle=0.0f;
  395.     }
  396.  
  397.     if (swing_angle>0.0f || swing_angle<0.0f)
  398.     {
  399.         swing_displacement=(GLfloat) (40.0f*abs(swing_angle));
  400.     }
  401.     else
  402.     {
  403.         swing_displacement=0.0f;
  404.     }
  405.  
  406.               gluLookAt(
  407.               objForce.m_xPos-((swing_displacement+30.0f)*(GLfloat)cos(objForce.m_angle_radians+swing_angle)+camera.m_x), 
  408.               objForce.m_yPos+camera.m_y, 
  409.               objForce.m_zPos+((swing_displacement+30.0f)*(GLfloat)sin(objForce.m_angle_radians+swing_angle)), 
  410.               objForce.m_xPos+(100.0f*(GLfloat)cos(objForce.m_angle_radians)+camera.m_z), 
  411.               objForce.m_yPos-20, 
  412.               objForce.m_zPos-(100.0f*(GLfloat)sin(objForce.m_angle_radians)), 
  413.               0.0f, 
  414.               1.0f, 
  415.               0.0f  
  416.               );
  417.  
  418.               /*
  419.       gluLookAt(
  420.       objForce.m_xPos-(30.0f*(GLfloat)cos(objForce.m_angle_radians)+camera.m_x), 
  421.       objForce.m_yPos+camera.m_y, 
  422.       objForce.m_zPos+(30.0f*(GLfloat)sin(objForce.m_angle_radians)), 
  423.       objForce.m_xPos+(100.0f*(GLfloat)cos(objForce.m_angle_radians)+camera.m_z), 
  424.       objForce.m_yPos-50, 
  425.       objForce.m_zPos-(100.0f*(GLfloat)sin(objForce.m_angle_radians)), 
  426.       0.0f, 
  427.       1.0f, 
  428.       0.0f  
  429.       );
  430.         */
  431.  
  432.     glPushMatrix();
  433.         glTranslatef(20.0f, 12.0f,0.0f);
  434.         glRotatef(-90.0f,0.0f,1.0f,0.0f);
  435.         glRotatef(90.0f,1.0f,0.0f,0.0f);
  436.         m_FontX.GLDrawText();
  437.     glPopMatrix();
  438.  
  439.     VERIFY( pFrame = (CMainFrame*)GetParentFrame() ); 
  440.  
  441.     if ((objForce.m_shield<0) || (mLives<0))
  442.     {
  443.         gameOver=TRUE;
  444.     }
  445.     else
  446.     {
  447.         sprintf(scorePhrase,"(space)fire (1-5) camera (Score)%i (Shield) %i (Lives) %i",objForce.m_score,objForce.m_shield,mLives);
  448.     }
  449.  
  450.     if(gameOver)
  451.     {
  452.         sprintf(scorePhrase,"Game Over Score %i",objForce.m_score);
  453.         pFrame->SetWindowText(scorePhrase); 
  454.     }
  455.     else
  456.     {
  457.         pFrame->SetWindowText(scorePhrase); 
  458.     }
  459.  
  460.     traverseSceneGraph(root);
  461.  
  462.     glPushMatrix();
  463.         glTranslatef(0.0f,-10.0f,0.0f);
  464.         drawGrid();
  465.     glPopMatrix();
  466.     
  467.     generateAsteroid();
  468.  
  469.     drawForceMissiles();
  470.  
  471.     drawForceAsteroids();
  472.  
  473.     if(getObjectCount(BONUS_TYPE)>0)
  474.     {
  475.         drawBonusObjectList();
  476.     }
  477.     else
  478.     {
  479.         buildBonusObject();
  480.         drawBonusObjectList();
  481.         mLives+=2;
  482.     }
  483.  
  484.     generateMines();
  485.  
  486.     drawMineObjectList();
  487.  
  488.     drawExplosion();
  489.  
  490. }
  491. void CMy3DFontView::setLighting()
  492. {
  493.   GLfloat light0pos[4]=     {0.7071f, 40.0f, 5.0f, 1.0f};
  494.   GLfloat light0ambient[4]= {0.3f, 0.3f, 0.3f, 1.0f};
  495.   GLfloat light0diffuse[4]= {0.6f, 0.6f, 0.6f, 1.0f};
  496.   GLfloat light0specular[4]={0.8f, 0.8f, 0.8f, 1.0f};
  497.   GLfloat lmodel_ambient[]= {0.5f,0.5f,0.5f,1.0f};
  498.  
  499.   glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient);
  500.  
  501.   //glDisable(GL_DITHER);
  502.   glShadeModel(GL_SMOOTH);
  503.   
  504.   glLightfv(GL_LIGHT0, GL_POSITION, light0pos);
  505.   glLightfv(GL_LIGHT0, GL_AMBIENT, light0ambient);
  506.   glLightfv(GL_LIGHT0, GL_DIFFUSE, light0diffuse);
  507.   glLightfv(GL_LIGHT0, GL_SPECULAR, light0specular);
  508.   
  509.   glEnable(GL_LIGHTING);
  510.   glEnable(GL_LIGHT0);
  511. }
  512. void CMy3DFontView::setBlending()
  513. {
  514.     glEnable(GL_BLEND);
  515.     /*GL_SRC_ALPHA = Source color multiplied by source alpha
  516.       GL_ONE_MINUS_SRC_ALPHA =  Destination color is multiplied by 1,1,1,1 - source color)
  517.     */
  518.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  519.  
  520. }
  521.  
  522. /////////////////////////////////////////////////////////////////////////////
  523. // CMy3DFontView diagnostics
  524.  
  525. #ifdef _DEBUG
  526. void CMy3DFontView::AssertValid() const
  527. {
  528.     CView::AssertValid();
  529. }
  530.  
  531. void CMy3DFontView::Dump(CDumpContext& dc) const
  532. {
  533.     CView::Dump(dc);
  534. }
  535.  
  536. CMy3DFontDoc* CMy3DFontView::GetDocument() // non-debug version is inline
  537. {
  538.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy3DFontDoc)));
  539.     return (CMy3DFontDoc*)m_pDocument;
  540. }
  541. #endif //_DEBUG
  542.  
  543. /////////////////////////////////////////////////////////////////////////////
  544. // CMy3DFontView message handlers
  545.  
  546. int CMy3DFontView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  547. {
  548.     if (CView::OnCreate(lpCreateStruct) == -1)
  549.         return -1;
  550.     
  551.     // TODO: Add your specialized creation code here
  552.     PIXELFORMATDESCRIPTOR pfd =
  553.     {
  554.         sizeof(PIXELFORMATDESCRIPTOR),
  555.         1,
  556.         PFD_DRAW_TO_WINDOW|
  557.         PFD_SUPPORT_OPENGL|
  558.         PFD_DOUBLEBUFFER,  
  559.         PFD_TYPE_RGBA,
  560.         24,
  561.         0,0,0,0,0,0,
  562.         0,0,0,0,0,0,0,
  563.         32,
  564.         0,0,
  565.         PFD_MAIN_PLANE,
  566.         0,
  567.         0,0,0
  568.     };
  569.      
  570.     m_pDC = new CClientDC(this);
  571.     int pixelFormat =
  572.         ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
  573.     BOOL success = 
  574.         SetPixelFormat(m_pDC->GetSafeHdc(), pixelFormat, &pfd);
  575.  
  576.     DescribePixelFormat(m_pDC->GetSafeHdc(), pixelFormat,
  577.           sizeof(pfd), &pfd);
  578.  
  579.     if(pfd.dwFlags & PFD_NEED_PALETTE)
  580.          InitPalette();
  581.  
  582.     m_hRC = wglCreateContext(m_pDC->GetSafeHdc());
  583.  
  584.     m_FontX.SetXOffset(0.0f);
  585.     m_FontX.SetYOffset(0.1f);
  586.     m_FontX.SetXScale(6.4f);
  587.     m_FontX.SetYScale(6.3f);
  588.     m_FontX.SetZScale(3.8f);
  589.     m_FontX.SetXRotate(-90.0f);
  590.     m_FontX.SetYRotate(0.0f);
  591.     m_FontX.SetZRotate(0.0f);
  592.  
  593.     InitFontColor();
  594.  
  595.     wglMakeCurrent(m_pDC->m_hDC,m_hRC);
  596.     m_FontX.CreateFont(m_pDC, "Arial Black");
  597.     m_FontX.SetText("Force");
  598.  
  599.     wglMakeCurrent(NULL,NULL);
  600.  
  601.     setSpeed();
  602.  
  603.     return 0;
  604. }
  605.  
  606. void CMy3DFontView::OnDestroy() 
  607. {
  608.     CView::OnDestroy();
  609.     
  610.     // TODO: Add your message handler code here
  611.     wglDeleteContext(m_hRC);
  612.     m_Palette.DeleteObject();
  613.     ReleaseDC(m_pDC);
  614. }
  615.  
  616. void CMy3DFontView::OnSize(UINT nType, int cx, int cy) 
  617. {
  618.     GLdouble aspect;
  619.     CView::OnSize(nType, cx, cy);
  620.  
  621.     if (cy==0)
  622.         aspect = (GLdouble)cx;
  623.     else
  624.         aspect = (GLdouble)cx/(GLdouble)cy;
  625.  
  626.     CClientDC clientDC(this);
  627.     wglMakeCurrent(clientDC.m_hDC, m_hRC);
  628.     glMatrixMode(GL_PROJECTION);
  629.     glLoadIdentity();
  630.     //glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 7.0);
  631.     //glViewport(0, 0, cx, cy);
  632.  
  633.     setPerspectiveWindow(60,aspect,5,4000);
  634.     setViewport(0,0,cx,cy);
  635.     
  636.     wglMakeCurrent(NULL, NULL);
  637. }
  638.  
  639.  
  640. void CMy3DFontView::InitPalette(void)
  641. {
  642.     PIXELFORMATDESCRIPTOR pfd;  // Pixel Format Descriptor         
  643.     LOGPALETTE *pPal;            // Pointer to memory for logical palette
  644.     int PixelFormat;            // Pixel format index
  645.     int paletteSize;            // Number of entries in palette 
  646.     BYTE RedMask;               // Range for each color entry (7,7,and 3)
  647.     BYTE GreenMask;
  648.     BYTE BlueMask;
  649.     HDC hDC = GetDC()->GetSafeHdc();  //the context device                                 
  650.  
  651.     // Get the pixel format index and retrieve the pixel format description
  652.     PixelFormat = GetPixelFormat(hDC);
  653.     DescribePixelFormat(hDC, PixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  654.     
  655.     
  656.     // Check whether the pixel format and the pixel type
  657.     if (!(pfd.dwFlags & PFD_NEED_PALETTE ||
  658.       pfd.iPixelType == PFD_TYPE_COLORINDEX))
  659.         return;
  660.  
  661.     // Get the number of entries in palette. 256 colors for 8 bits 
  662.     paletteSize = 1 << pfd.cColorBits;
  663.     
  664.     // Allocate for the logical palette
  665.     pPal = (LOGPALETTE*)
  666.     malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
  667.     
  668.     
  669.     // Fill the logical palette header information 
  670.     pPal->palVersion = 0x300;            //support Windows3.0
  671.     pPal->palNumEntries = paletteSize;   //number of colors entries
  672.  
  673.     // Set the 1st entries of logical palette with the current system palette 
  674.     (void) GetSystemPaletteEntries(hDC, 0, paletteSize, &pPal->palPalEntry[0]);
  675.  
  676.     //Set the RGB mask
  677.     RedMask = (1 << pfd.cRedBits) - 1;
  678.     GreenMask = (1 << pfd.cGreenBits) - 1;
  679.     BlueMask = (1 << pfd.cBlueBits) - 1;
  680.  
  681.     //Set all entries of the logical palette 
  682.     for (int i=0; i<paletteSize; ++i) 
  683.     {
  684.         pPal->palPalEntry[i].peRed =
  685.             (((i >> pfd.cRedShift) & RedMask) * 255) / RedMask;
  686.         pPal->palPalEntry[i].peGreen =
  687.             (((i >> pfd.cGreenShift) & GreenMask) * 255) / GreenMask;
  688.         pPal->palPalEntry[i].peBlue =
  689.             (((i >> pfd.cBlueShift) & BlueMask) * 255) / BlueMask;
  690.         pPal->palPalEntry[i].peFlags = 0;
  691.     }
  692.  
  693.     //Create the palette
  694.     m_Palette.CreatePalette(pPal);
  695.  
  696.     //Free the memory allocated for the logical palette 
  697.     free(pPal);
  698. }
  699.  
  700.  
  701. void CMy3DFontView::DrawGLFont(void)
  702. {
  703.     glShadeModel(GL_SMOOTH);
  704.     glEnable(GL_DEPTH_TEST);
  705.     
  706.     //clear color buffer
  707.     glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  708.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  709.     
  710.     //set light model
  711.     glEnable(GL_LIGHTING);
  712.     glEnable(GL_LIGHT0);
  713.  
  714.     glMatrixMode(GL_MODELVIEW);
  715.     glLoadIdentity();
  716.  
  717.     //glTranslatef(-3.0f, -5.0f, -0.0f);
  718.  
  719.     m_FontX.GLDrawText();
  720.  
  721.     glFlush();
  722.  
  723. }
  724.  
  725.  
  726. void CMy3DFontView::InitFontColor()
  727. {
  728.     float fv[4];
  729.  
  730.  
  731.     fv[0] = 0.1f;
  732.     fv[1] = 0.1f;
  733.     fv[2] = 0.1f;
  734.     fv[3] = 0.1f;
  735.     m_FontX.SetEmission(fv);
  736.  
  737.     fv[0] = 0.9f;
  738.     fv[1] = 0.9f;
  739.     fv[2] = 0.9f;
  740.     fv[3] = 1.0f;
  741.     m_FontX.SetSpecular(fv);
  742.  
  743.     fv[0] = 0.1f;
  744.     fv[1] = 0.1f;
  745.     fv[2] = 1.0f;
  746.     fv[3] = 1.0f;
  747.     m_FontX.SetAmbient(fv);
  748.  
  749.     fv[0] = 0.1f;
  750.     fv[1] = 0.1f;
  751.     fv[2] = 0.1f;
  752.     fv[3] = 1.0f;
  753.     m_FontX.SetDiffuse(fv);
  754.  
  755.     m_FontX.SetShininess(0.1f);
  756.     
  757. }
  758.  
  759.  
  760. void CMy3DFontView::setPerspectiveWindow(GLdouble fovy, GLdouble aspect,GLdouble zNear,GLdouble zFar)
  761. {
  762.   glMatrixMode(GL_PROJECTION);
  763.   glLoadIdentity();
  764.   gluPerspective(fovy, aspect,zNear,  zFar);
  765. }
  766. void CMy3DFontView::setViewport(GLint iX, GLint iY, GLsizei iWidth, GLsizei iHeight)
  767. {
  768.     glViewport(iX,iY,iWidth,iHeight);
  769. }
  770. void CMy3DFontView::setDepthBuffer()
  771. {
  772.   glEnable(GL_DEPTH_TEST);
  773.   glDepthFunc(GL_LESS);
  774.   glEnable(GL_CULL_FACE);
  775.   glCullFace(GL_BACK);
  776.   glFrontFace(GL_CCW);
  777. }
  778. void CMy3DFontView::startGame()
  779. {
  780.     gameOver = FALSE;
  781.     objForce.m_score=0;
  782.     mLives=3;
  783.     objForce.m_shield=100;
  784.  
  785.     camera.m_angle_radians=(float)1.57;
  786.     camera.m_x=0.0f;;
  787.     camera.m_y=14.0f;
  788.     camera.m_z=0.0f;
  789.  
  790. }
  791.  
  792.  
  793. void CMy3DFontView::OnTimer(UINT nIDEvent) 
  794. {
  795.     // TODO: Add your message handler code here and/or call default
  796.  
  797.     if(pause)
  798.     {
  799.         KillTimer(1);
  800.     }
  801.     else
  802.     {
  803.         setSpeed();
  804.     }
  805.  
  806.     Invalidate(FALSE);
  807.  
  808.     CView::OnTimer(nIDEvent);
  809. }
  810.  
  811. void CMy3DFontView::forceLeft()
  812. {
  813.     objForce.m_angle_radians +=(GLfloat) PI/25.0f; 
  814.     if(objForce.m_angle_radians > (2.0*PI))        // Keep in bounds
  815.         objForce.m_angle_radians = 0.0f;
  816.  
  817. }
  818. void CMy3DFontView::forceRight(void)
  819. {
  820.     objForce.m_angle_radians -= (GLfloat) PI/25.0f; 
  821.     if (objForce.m_angle_radians <0.0f)        // Keep in bounds
  822.        objForce.m_angle_radians = (GLfloat)(2.0f*PI);
  823. }
  824.  
  825. void CMy3DFontView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  826. {
  827.     static clock_t current_clicks=clock();
  828.  
  829.     // TODO: Add your message handler code here and/or call default
  830.         //left
  831.         if (nChar==37)
  832.         {
  833.             forceLeft();
  834.         }
  835.         //right
  836.         else if(nChar==39)
  837.         {
  838.             forceRight();
  839.         }
  840.         //up
  841.         else if(nChar==38)
  842.         {
  843.             if (objForce.m_delta<10)
  844.                 objForce.m_delta+=1;
  845.         }
  846.         //down
  847.         else if(nChar==40)
  848.         {
  849.             if (objForce.m_delta>-10)
  850.                 objForce.m_delta-=1;
  851.         }
  852.         //fire
  853.         else if(nChar==32)
  854.         {
  855.             if((clock()-current_clicks)>500)
  856.             {
  857.                 fireForceBall((GLfloat) (dRadToDeg(objForce.m_angle_radians+((float)PI/2.0f))+180),0.0f,1.0f);
  858.                 current_clicks=clock();
  859.             }
  860.         }
  861.         //1
  862.         else if(nChar==49)
  863.         {
  864.             objForce.m_swing=LEFT;
  865.         }
  866.             //2
  867.         else if(nChar==50)
  868.         {
  869.             objForce.m_swing=CENTER;
  870.         }
  871.             //3
  872.         else if(nChar==51)
  873.         {
  874.             objForce.m_swing=RIGHT;
  875.         }
  876.             //4
  877.         else if(nChar==52)
  878.         {
  879.             camera.m_y++;
  880.         }
  881.             //5
  882.         else if(nChar==53)
  883.         {
  884.             camera.m_y--;
  885.         }
  886.             //6
  887.         else if(nChar==54)
  888.         {
  889.         }
  890.             //7
  891.         else if(nChar==55)
  892.         {
  893.         }
  894.             //8
  895.         else if (nChar==56)
  896.         {
  897.             
  898.         }
  899.  
  900.     //Invalidate(FALSE);
  901.     CView::OnKeyDown(nChar, nRepCnt, nFlags);
  902. }
  903. void CMy3DFontView::drawGrid()
  904. {
  905. int r,c;
  906. int nStep = 10;
  907. int size=GRID_SIZE;
  908.  
  909.  
  910.   glPushAttrib(GL_LIGHTING);
  911.   glDisable(GL_LIGHTING);
  912.   glRGB(0,255,0);
  913.  
  914.   glPushMatrix();
  915.  
  916.     /* Just draw a bunch of horizontal and vertical lines */
  917.     glBegin(GL_LINES);
  918.  
  919.     for(r = -size; r  <= size; r += nStep)
  920.         {
  921.         glVertex3f((float)r, 0.0f, (float)-size);
  922.         glVertex3f((float)r, 0.0f, (float)size);
  923.         }
  924.  
  925.     for(c = -size; c <= size; c += nStep)
  926.         {
  927.         glVertex3f((float)size, 0.0f, (float)c);
  928.         glVertex3f((float)-size, 0.0f, (float)c);
  929.         }
  930.  
  931.     glEnd();
  932.  
  933.   glPopMatrix();
  934.  
  935.   glPopAttrib();
  936.   glEnable(GL_LIGHTING);
  937. }
  938.  
  939. void CMy3DFontView::OnFilePause() 
  940. {
  941.     // TODO: Add your command handler code here
  942.     pause=TRUE;
  943. }
  944. void CMy3DFontView::setSpeed()
  945. {
  946.     SetTimer(1,100,0);
  947. }
  948.  
  949. void CMy3DFontView::OnFileNew() 
  950. {
  951.     // TODO: Add your command handler code here
  952.     startGame();
  953. }
  954.  
  955. void CMy3DFontView::OnFileResume() 
  956. {
  957.     // TODO: Add your command handler code here
  958.  
  959.         pause=FALSE;
  960.         setSpeed();
  961. }
  962. void CMy3DFontView::traverseSceneGraph(treenode *root)
  963. {
  964.     if(root==NULL)
  965.         return;
  966.     //count++;
  967.     //printf("PushMatrix %d\n",count);
  968.     //printf("%s\n",root->node_key);
  969.     glPushMatrix();
  970.         //glMultMatrix(root->m);
  971.         root->f();
  972.         if (root->engine!=NULL)
  973.         {
  974.             root->engine();
  975.         }
  976.         if(root->child!=NULL)
  977.         {
  978.             traverseSceneGraph(root->child);
  979.         }
  980.     //count--;
  981.     //printf("PopMatrix %d\n",count);
  982.  
  983.     glPopMatrix();
  984.     
  985.     if(root->sibling!=NULL)
  986.             traverseSceneGraph(root->sibling);
  987. }
  988. treenode* CMy3DFontView::node(char *node_key)
  989. {
  990.     treenode *retNode;
  991.  
  992.     retNode=(treenode *) malloc (sizeof(treenode));
  993.     retNode->child=NULL;
  994.     retNode->sibling=NULL;
  995.     retNode->engine=NULL;
  996.     retNode->most_recent_child=NULL;
  997.     strcpy(retNode->node_key,node_key);
  998.  
  999.     return(retNode);
  1000.  
  1001. }
  1002. void CMy3DFontView::addChild(treenode *parentNode, treenode *childNode)
  1003. {
  1004.     /*
  1005.     Observations
  1006.     1) addChild rules:
  1007.     a) A parent has only one child
  1008.     b) If another child is associated to the parent it becomes a sibling of the parents first child.  That child becomes the parent's most_recent_child.  Any additional children are associated to the parent's most_recent_child sibling link.
  1009.     c) The parents first child sibling link is traverse to find all remaining children.  This is the key for the algorithm to work correctly.
  1010.     */
  1011.  
  1012.     treenode *most_recent_child;
  1013.     //walk down the tree from the topmost child
  1014.     //connect the sibling link from the most recent child
  1015.     most_recent_child=parentNode->most_recent_child;
  1016.     
  1017.     strcpy(childNode->parent_key,parentNode->node_key);
  1018.  
  1019.     if (most_recent_child!=NULL)
  1020.     {
  1021.         most_recent_child->sibling=childNode;
  1022.         parentNode->most_recent_child=childNode;
  1023.     }
  1024.     //first child
  1025.     else
  1026.     {
  1027.         parentNode->child=childNode;
  1028.         parentNode->most_recent_child=childNode;
  1029.     }
  1030. }
  1031. void CMy3DFontView::cleanSceneGraph(treenode *root)
  1032. {
  1033.     if(root->child!=NULL)
  1034.         cleanSceneGraph(root->child);
  1035.     
  1036.     if(root->sibling!=NULL)
  1037.         cleanSceneGraph(root->sibling);
  1038.  
  1039.     free(root);
  1040. }
  1041. void CMy3DFontView::buildSceneGraph()
  1042. {
  1043.     treenode *objTieFighter, *objTieFighterBody;
  1044.     treenode *objEnemy, *objEnemyBody;
  1045.  
  1046.     root=node("root");
  1047.     root->f=force;
  1048.  
  1049.     objTieFighter=node("TieFighter");
  1050.     objTieFighter->f=tieFighter;
  1051.     objTieFighter->engine=empty;
  1052.     addChild(root,objTieFighter);
  1053.  
  1054.     objTieFighterBody=node("TieFighterBody");
  1055.     objTieFighterBody->f=drawTieFighter;
  1056.     objTieFighter->engine=empty;
  1057.     addChild(objTieFighter,objTieFighterBody);
  1058.  
  1059.     objEnemy=node("Enemy");
  1060.     objEnemy->f=Enemy;
  1061.     objEnemy->engine=Enemy_engine;
  1062.     addChild(root,objEnemy);
  1063.  
  1064.     objEnemyBody=node("Enemy Body");
  1065.     objEnemyBody->f=drawEnemy;
  1066.     objEnemyBody->engine=NULL;
  1067.     addChild(objEnemy,objEnemyBody);
  1068.  
  1069. }
  1070. void cylinder(GLfloat radius,GLfloat height)
  1071. {
  1072. GLUquadricObj *obj = gluNewQuadric();
  1073. gluQuadricDrawStyle(obj,GLU_FILL);
  1074. gluQuadricNormals(obj,GLU_SMOOTH);
  1075. gluQuadricOrientation(obj,GLU_OUTSIDE);
  1076. gluQuadricTexture(obj, GL_TRUE);
  1077.  
  1078. /*Base Cylinder*/
  1079. glPushMatrix();
  1080.     /* Rotate about the X axis */
  1081.     glRotatef(90.0f,1.0f,0.0f,0.0f);
  1082.     /* qobj = quadric object
  1083.     baseRadius
  1084.     topRadius
  1085.     height,
  1086.     slices (Subdivisions around the Z axis)
  1087.     stacks (Subdivisions around the Z axis)
  1088.     */
  1089.     gluCylinder(obj,radius,radius,height,10,1);
  1090. glPopMatrix(); 
  1091. /* Lid*/
  1092. glPushMatrix(); 
  1093.     glRotatef(-90.0f,1.0f,0.0f,0.0f);
  1094.     /* qobj = quadric object
  1095.     innerRadius = Inner radius of the disk
  1096.     outerRadius = Outer radius of the disk
  1097.     slices = number of subdivisions around the Z axis
  1098.     loops = number of concentric rings about the origin
  1099.     */
  1100.     gluDisk(obj,0.0f,radius,10,2);
  1101. glPopMatrix();
  1102.     /*Bottom*/
  1103. glPushMatrix(); 
  1104.     glTranslatef(0.0f,-height,0.0f);
  1105.     glRotatef(90.0f,1.0f,0.0f,0.0f);
  1106.     /* qobj = quadric object
  1107.     innerRadius = Inner radius of the disk
  1108.     outerRadius = Outer radius of the disk
  1109.     slices = number of subdivisions around the Z axis
  1110.     loops = number of concentric rings about the origin
  1111.     */
  1112.     gluDisk(obj,0.0f,radius,10,2);
  1113. glPopMatrix();
  1114.  
  1115. gluDeleteQuadric(obj);
  1116. }
  1117. void cone(GLfloat radius,GLfloat height)
  1118. {
  1119. GLUquadricObj *obj = gluNewQuadric();
  1120. gluQuadricDrawStyle(obj,GLU_FILL);
  1121. gluQuadricNormals(obj,GLU_SMOOTH);
  1122. gluQuadricOrientation(obj,GLU_OUTSIDE);
  1123. gluQuadricTexture(obj, GL_TRUE);
  1124.  
  1125. /*Base Cylinder*/
  1126. glPushMatrix();
  1127.     /* Rotate about the X axis */
  1128.     glRotatef(90.0f,1.0f,0.0f,0.0f);
  1129.     /* qobj = quadric object
  1130.     baseRadius
  1131.     topRadius
  1132.     height,
  1133.     slices (Subdivisions around the Z axis)
  1134.     stacks (Subdivisions around the Z axis)
  1135.     */
  1136.     gluCylinder(obj,0,radius,height,10,1);
  1137. glPopMatrix(); 
  1138.  
  1139. /*Bottom*/
  1140. glPushMatrix(); 
  1141.     glTranslatef(0.0f,-height,0.0f);
  1142.     glRotatef(90.0f,1.0f,0.0f,0.0f);
  1143.     /* qobj = quadric object
  1144.     innerRadius = Inner radius of the disk
  1145.     outerRadius = Outer radius of the disk
  1146.     slices = number of subdivisions around the Z axis
  1147.     loops = number of concentric rings about the origin
  1148.     */
  1149.     gluDisk(obj,0.0f,radius,10,2);
  1150. glPopMatrix();
  1151. gluDeleteQuadric(obj);
  1152. }
  1153. void box(GLfloat w,GLfloat h,GLfloat d)
  1154. {
  1155.     glBegin(GL_POLYGON);
  1156.         glNormal3f(0.0f,0.0f,1.0f);
  1157.         glTexCoord2f(0.0f, 1.0f);
  1158.         glVertex3f(1.0f*w,    1.0f*h,    1.0f*d);
  1159.         glTexCoord2f(0.0f, 0.0f);
  1160.         glVertex3f(-1.0f*w,    1.0f*h,    1.0f*d);
  1161.         glTexCoord2f(1.0f, 0.0f);
  1162.         glVertex3f(-1.0f*w,    -1.0f*h,    1.0f*d);
  1163.         glTexCoord2f(1.0f, 1.0f);
  1164.         glVertex3f(1.0f*w,    -1.0f*h,    1.0f*d);
  1165.     glEnd();
  1166.  
  1167.     glBegin(GL_POLYGON);
  1168.         glNormal3f(0.0f,0.0f,-1.0f);
  1169.         glTexCoord2f(0.0f, 1.0f);
  1170.         glVertex3f(1.0f*w,    1.0f*h,    -1.0f*d);
  1171.         glTexCoord2f(0.0f, 0.0f);
  1172.         glVertex3f(1.0f*w,    -1.0f*h,    -1.0f*d);
  1173.         glTexCoord2f(1.0f, 0.0f);
  1174.         glVertex3f(-1.0f*w,    -1.0f*h,    -1.0f*d);
  1175.         glTexCoord2f(1.0f, 1.0f);
  1176.         glVertex3f(-1.0f*w,    1.0f*h,    -1.0f*d);
  1177.     glEnd();
  1178.  
  1179.     glBegin(GL_POLYGON);
  1180.         glNormal3f(-1.0f,0.0f,0.0f);
  1181.         glTexCoord2f(0.0f, 1.0f);
  1182.         glVertex3f(-1.0f*w,    1.0f*h,    1.0f*d);
  1183.         glTexCoord2f(0.0f, 0.0f);
  1184.         glVertex3f(-1.0f*w,    1.0f*h,    -1.0f*d);
  1185.         glTexCoord2f(1.0f, 0.0f);
  1186.         glVertex3f(-1.0f*w,    -1.0f*h,    -1.0f*d);
  1187.         glTexCoord2f(1.0f, 1.0f);
  1188.         glVertex3f(-1.0f*w,    -1.0f*h,    1.0f*d);
  1189.     glEnd();
  1190.  
  1191.     glBegin(GL_POLYGON);
  1192.         glNormal3f(1.0f,0.0f,0.0f);
  1193.         glTexCoord2f(0.0f, 1.0f);
  1194.         glVertex3f(1.0f*w,    1.0f*h,    1.0f*d);
  1195.         glTexCoord2f(0.0f, 0.0f);
  1196.         glVertex3f(1.0f*w,    -1.0f*h,    1.0f*d);
  1197.         glTexCoord2f(1.0f, 0.0f);
  1198.         glVertex3f(1.0f*w,    -1.0f*h,    -1.0f*d);
  1199.         glTexCoord2f(1.0f, 1.0f);
  1200.         glVertex3f(1.0f*w,    1.0f*h,    -1.0f*d);
  1201.     glEnd();
  1202.  
  1203.     glBegin(GL_POLYGON);
  1204.         glNormal3f(0.0f,1.0f,0.0f);
  1205.         glTexCoord2f(0.0f, 1.0f);
  1206.         glVertex3f(-1.0f*w,    1.0f*h,    -1.0f*d);
  1207.         glTexCoord2f(0.0f, 0.0f);
  1208.         glVertex3f(-1.0f*w,    1.0f*h,    1.0f*d);
  1209.         glTexCoord2f(1.0f, 0.0f);
  1210.         glVertex3f(1.0f*w,    1.0f*h,    1.0f*d);
  1211.         glTexCoord2f(1.0f, 1.0f);
  1212.         glVertex3f(1.0f*w,    1.0f*h,    -1.0f*d);
  1213.     glEnd();
  1214.  
  1215.     glBegin(GL_POLYGON);
  1216.         glNormal3f(0.0f,-1.0f,0.0f);
  1217.         glTexCoord2f(0.0f, 1.0f);
  1218.         glVertex3f(-1.0f*w,    -1.0f*h,    -1.0f*d);
  1219.         glTexCoord2f(0.0f, 0.0f);
  1220.         glVertex3f(1.0f*w,    -1.0f*h,    -1.0f*d);
  1221.         glTexCoord2f(1.0f, 0.0f);
  1222.         glVertex3f(1.0f*w,    -1.0f*h,    1.0f*d);
  1223.         glTexCoord2f(1.0f, 1.0f);
  1224.         glVertex3f(-1.0f*w,    -1.0f*h,    1.0f*d);
  1225.     glEnd();
  1226.  
  1227. }
  1228. void brassMaterial()
  1229. {
  1230.       setAmbientMaterialColor(0.329412f,0.223529f,0.027451f,1.0f);
  1231.       setDiffuseMaterialColor(0.780392f,0.568627f,0.113725f,1.0f);
  1232.       setSpecularMaterialColor(0.992157f,0.941176f,0.807843f,1.0f);
  1233.       setMaterialShininess(27.8974f);
  1234. }
  1235. void pewterMaterial()
  1236. {
  1237.     setAmbientMaterialColor(0.10588f,0.058824f,0.113725f,1.0f);
  1238.     setDiffuseMaterialColor(0.427451f,0.470588f,0.541176f,1.0f);
  1239.     setSpecularMaterialColor(0.3333f,0.3333f,0.521569f,1.0f);
  1240.     setMaterialShininess(9.84615f);
  1241. }
  1242. void blackPlasticMaterial()
  1243. {
  1244.     setAmbientMaterialColor(0.0f,0.0f,0.0f,1.0f);
  1245.     setDiffuseMaterialColor(0.01f,0.01f,0.01f,1.0f);
  1246.     setSpecularMaterialColor(0.50f,0.50f,0.50f,1.0f);
  1247.     //setMaterialShininess(32);
  1248.     setMaterialShininess(64.0f);
  1249. }
  1250. void goldMaterial()
  1251. {
  1252.     setAmbientMaterialColor(0.24725f,0.1995f,0.0745f,1.0f);
  1253.     setDiffuseMaterialColor(0.75164f,0.60648f,0.22648f,1.0f);
  1254.     setSpecularMaterialColor(0.628281f,0.555802f,0.366065f,1.0f);
  1255.     setMaterialShininess(100.0f);
  1256. }
  1257. void bronzeMaterial()
  1258. {
  1259.     setAmbientMaterialColor(0.2125f,0.1275f,0.054f,1.0f);
  1260.     setDiffuseMaterialColor(0.714f,0.4284f,0.18144f,1.0f);
  1261.     setSpecularMaterialColor(0.393548f,0.271906f,0.166721f,1.0f);
  1262.     setMaterialShininess(25.6f);
  1263. }
  1264. void chromeMaterial()
  1265. {
  1266.     setAmbientMaterialColor(0.25f,0.25f,0.25f,1.0f);
  1267.     setDiffuseMaterialColor(0.4f,0.4f,0.4f,1.0f);
  1268.     setSpecularMaterialColor(0.774597f,0.774597f,0.774597f,1.0f);
  1269.     setMaterialShininess(76.8f);
  1270. }
  1271. void copperMaterial()
  1272. {
  1273.     setAmbientMaterialColor(0.19125f,0.0735f,0.0225f,1.0f);
  1274.     setDiffuseMaterialColor(0.7038f,0.27048f,0.0828f,1.0f);
  1275.     setSpecularMaterialColor(0.256777f,0.137622f,0.086014f,1.0f);
  1276.     setMaterialShininess(12.8f);
  1277. }
  1278. void silverMaterial()
  1279. {
  1280.     setAmbientMaterialColor(0.19125f,0.19225f,0.19225f,1.0f);
  1281.     setDiffuseMaterialColor(0.50754f,0.50754f,0.50754f,1.0f);
  1282.     setSpecularMaterialColor(0.508273f,0.508273f,0.508273f,1.0f);
  1283.     setMaterialShininess(51.2f);
  1284. }
  1285. void setDiffuseMaterialColor(GLfloat red, GLfloat green, GLfloat blue,GLfloat alpha)
  1286. {
  1287.     GLfloat diff[4];
  1288.     diff[0]=red;
  1289.     diff[1]=green;
  1290.     diff[2]=blue;
  1291.     diff[3]=alpha;
  1292.     glMaterialfv(GL_FRONT, GL_DIFFUSE,diff); 
  1293.  
  1294. }
  1295. void setAmbientMaterialColor(GLfloat red, GLfloat green, GLfloat blue,GLfloat alpha)
  1296. {
  1297.     GLfloat amb[4];
  1298.     amb[0]=red;
  1299.     amb[1]=green;
  1300.     amb[2]=blue;
  1301.     amb[3]=alpha;
  1302.     glMaterialfv(GL_FRONT, GL_AMBIENT,amb); 
  1303.  
  1304. }
  1305. void setSpecularMaterialColor(GLfloat red, GLfloat green, GLfloat blue,GLfloat alpha)
  1306. {
  1307.     GLfloat spec[4];
  1308.     spec[0]=red;
  1309.     spec[1]=green;
  1310.     spec[2]=blue;
  1311.     spec[3]=alpha;
  1312.     glMaterialfv(GL_FRONT, GL_SPECULAR,spec); 
  1313.  
  1314. }
  1315. void setMaterialShininess(GLfloat shininess)
  1316. {
  1317.     glMateriali(GL_FRONT, GL_SHININESS, (GLint) shininess);
  1318. }
  1319. void sphere(GLfloat radius)
  1320. {
  1321.     GLUquadricObj *obj = gluNewQuadric();
  1322.     gluQuadricDrawStyle(obj,GLU_FILL);
  1323.     gluQuadricNormals(obj,GLU_SMOOTH);
  1324.     gluQuadricOrientation(obj,GLU_OUTSIDE);
  1325.     gluQuadricTexture(obj, GL_TRUE);
  1326.  
  1327.     gluSphere(obj, radius, 8, 8);
  1328.     gluDeleteQuadric(obj);
  1329. }
  1330.  
  1331. void point_sphere(GLfloat radius)
  1332. {
  1333.     GLUquadricObj *obj = gluNewQuadric();
  1334.     gluQuadricDrawStyle(obj,GLU_POINT);
  1335.     //gluQuadricDrawStyle(obj,GLU_FILL);
  1336.     //gluQuadricNormals(obj,GLU_SMOOTH);
  1337.     //gluQuadricOrientation(obj,GLU_OUTSIDE);
  1338.     //gluQuadricTexture(obj, GL_TRUE);
  1339.  
  1340.     gluSphere(obj, radius, 8, 8);
  1341.     gluDeleteQuadric(obj);
  1342. }
  1343.  
  1344. VECTOR_STRUCT_TYPE* rotate(GLfloat angle,GLfloat ux,GLfloat uy,GLfloat uz, VECTOR_STRUCT_TYPE *vector)
  1345. {
  1346. MATRIX4X4 Mt;
  1347. MATRIX1X4 Mp;
  1348. MATRIX1X4 Mr;
  1349.  
  1350. float sinTheta;
  1351. float cosTheta;
  1352. VECTOR_STRUCT_TYPE *ret_vector;
  1353.  
  1354. ret_vector= (VECTOR_STRUCT_TYPE *) malloc (sizeof(VECTOR_STRUCT_TYPE));
  1355.  
  1356. sinTheta=(float)sin(angle/180.0f*3.142);
  1357. cosTheta=(float)cos(angle/180.0f*3.142);
  1358.  
  1359. Mt[0][0]= cosTheta+(1-cosTheta)*pow(ux,2);
  1360. Mt[0][1]= (1-cosTheta)*uy*ux-sinTheta*uz; 
  1361. Mt[0][2]= (1-cosTheta)*uz*ux+sinTheta*uy;
  1362. Mt[0][3]= 0.0f;  
  1363.  
  1364. Mt[1][0]= (1-cosTheta)*ux*uy+sinTheta*uz;
  1365. Mt[1][1]= cosTheta+(1-cosTheta)*pow(uy,2);
  1366. Mt[1][2]= (1-cosTheta)*uz*uy-sinTheta*ux;
  1367. Mt[1][3]= 0.0f; 
  1368.  
  1369. Mt[2][0]= (1-cosTheta)*ux*uz-sinTheta*uy;
  1370. Mt[2][1]= (1-cosTheta)*uy*uz+sinTheta*ux;
  1371. Mt[2][2]= cosTheta+(1-cosTheta)*pow(uz,2);
  1372. Mt[2][3]= 0.0f;
  1373.  
  1374. Mt[3][0]=0;
  1375. Mt[3][1]=0;
  1376. Mt[3][2]=0;
  1377. Mt[3][3]=1;
  1378.  
  1379. Mp[0][0]=vector->m_x;
  1380. Mp[0][1]=vector->m_y;
  1381. Mp[0][2]=vector->m_z;
  1382. Mp[0][3]=1;
  1383.  
  1384.  
  1385. Matrix1X4_4X4(&Mr,&Mp,&Mt); 
  1386.  
  1387. ret_vector->m_x=(float)Mr[0][0];
  1388. ret_vector->m_y=(float)Mr[0][1];
  1389. ret_vector->m_z=(float)Mr[0][2];
  1390. return(ret_vector);
  1391.  
  1392. }
  1393.  
  1394. double Matrix4X1_1X4(MATRIX4X1 *matrix1, MATRIX1X4 *matrix2)
  1395. {
  1396. register int k;
  1397. double result=0.0;
  1398.     for (k = 0 ; k < 4 ; k++)
  1399.         result += (*matrix1)[k][0] * (*matrix2)[0][k];
  1400.     return(result);
  1401. }
  1402. void Matrix4X1_4X4(MATRIX4X1 *result, MATRIX4X1 *matrix1, MATRIX4X4 *matrix2)
  1403. {
  1404. register int i, k;
  1405. MATRIX4X1 temp_matrix;
  1406.     for (i = 0 ; i < 4 ; i++)
  1407.     {
  1408.     temp_matrix[i][0] = 0.0;
  1409.         for (k = 0 ; k < 4 ; k++)
  1410.         {
  1411.             temp_matrix[i][0] += (*matrix1)[k][0] * (*matrix2)[i][k];
  1412.         }
  1413.     }
  1414.     for (i = 0 ; i < 4 ; i++)
  1415.         (*result)[i][0] = temp_matrix[i][0];
  1416. }
  1417. void Matrix1X4_4X4(MATRIX1X4 *result, MATRIX1X4 *matrix1, MATRIX4X4 *matrix2)
  1418. {
  1419. register int i, k;
  1420. MATRIX4X1 temp_matrix;
  1421.     for (i = 0 ; i < 4 ; i++)
  1422.     {
  1423.         temp_matrix[i][0] = 0.0;
  1424.             for (k = 0 ; k < 4 ; k++)
  1425.             {
  1426.                 temp_matrix[i][0] += (*matrix1)[0][k] * (*matrix2)[i][k];
  1427.             }
  1428.     }
  1429.     for (i = 0 ; i < 4 ; i++)
  1430.         (*result)[0][i] = temp_matrix[i][0];
  1431. }
  1432. int getAvailableExplosion()
  1433. {
  1434.     int i;
  1435.     for(i=0; i<EXPLOSION_SIZE; i++)
  1436.     {
  1437.         if (objExplosion[i].m_available_flag==TRUE)
  1438.             objExplosion[i].m_active_flag=TRUE;
  1439.             objExplosion[i].m_available_flag=FALSE;
  1440.             return(i);
  1441.     }
  1442.     return(-1);
  1443.  
  1444. }
  1445. void torus(GLfloat innerRadius,    GLfloat outerRadius)
  1446. {
  1447.     GLfloat vertexes[4][3];
  1448.     GLfloat normal[3];
  1449.     GLfloat x;
  1450.     GLfloat y;
  1451.     GLfloat z;
  1452.     GLfloat phi;
  1453.     GLfloat theta;
  1454.     GLfloat CosPhi;
  1455.     GLfloat SinPhi;
  1456.     GLfloat SinTheta;
  1457.     GLfloat CosTheta;
  1458.  
  1459.     for(phi=0.0f; phi <= 360.0f; phi+=20.0f)
  1460.     {
  1461.         for(theta=0.0f; theta<=360.0f; theta+=20.0f)
  1462.         {
  1463.         CosPhi=(GLfloat)cos(phi/180.0*3.142);
  1464.         SinPhi=(GLfloat)sin(phi/180.0*3.142);
  1465.         CosTheta=(GLfloat)cos(theta/180.0*3.142);
  1466.         SinTheta=(GLfloat)sin(theta/180.0*3.142);
  1467.         /*Vertex 1*/
  1468.         x= CosTheta * (CosPhi * innerRadius+outerRadius);
  1469.         y= SinTheta * (CosPhi * innerRadius+outerRadius);
  1470.         z= (SinPhi) * innerRadius;
  1471.         vertexes[0][0]=x;
  1472.         vertexes[0][1]=y;
  1473.         vertexes[0][2]=z;
  1474.         /*Vertex 2*/
  1475.         CosPhi=(GLfloat)cos(phi/180.0*3.142);
  1476.         SinPhi=(GLfloat)sin(phi/180.0*3.142);
  1477.         CosTheta=(GLfloat)cos((theta+20)/180.0*3.142);
  1478.         SinTheta=(GLfloat)sin((theta+20)/180.0*3.142);
  1479.         x= CosTheta * (CosPhi * innerRadius+outerRadius);
  1480.         y= SinTheta * (CosPhi * innerRadius+outerRadius);
  1481.         z= (SinPhi) * innerRadius;
  1482.         vertexes[1][0]=x;
  1483.         vertexes[1][1]=y;
  1484.         vertexes[1][2]=z;
  1485.         /*Vertex 3*/
  1486.         CosPhi=(GLfloat)cos((phi+20)/180.0*3.142);
  1487.         SinPhi=(GLfloat)sin((phi+20)/180.0*3.142);
  1488.         CosTheta=(GLfloat)cos((theta+20)/180.0*3.142);
  1489.         SinTheta=(GLfloat)sin((theta+20)/180.0*3.142);
  1490.         x= CosTheta * (CosPhi * innerRadius+outerRadius);
  1491.         y= SinTheta * (CosPhi * innerRadius+outerRadius);
  1492.         z= (SinPhi) * innerRadius;
  1493.         vertexes[2][0]=x;
  1494.         vertexes[2][1]=y;
  1495.         vertexes[2][2]=z;
  1496.         /*Vertex 4*/
  1497.         CosPhi=(GLfloat)cos((phi+20)/180.0*3.142);
  1498.         SinPhi=(GLfloat)sin((phi+20)/180.0*3.142);
  1499.         CosTheta=(GLfloat)cos((theta)/180.0*3.142);
  1500.         SinTheta=(GLfloat)sin((theta)/180.0*3.142);
  1501.         x= CosTheta * (CosPhi * innerRadius+outerRadius);
  1502.         y= SinTheta * (CosPhi * innerRadius+outerRadius);
  1503.         z= (SinPhi) * innerRadius;
  1504.         vertexes[3][0]=x;
  1505.         vertexes[3][1]=y;
  1506.         vertexes[3][2]=z;
  1507.         calcNormal(vertexes,normal);
  1508.         glBegin(GL_POLYGON);
  1509.             glNormal3f(normal[0],normal[1],normal[2]);
  1510.             glVertex3f(vertexes[0][0],vertexes[0][1],vertexes[0][2]);
  1511.             glVertex3f(vertexes[1][0],vertexes[1][1],vertexes[1][2]);
  1512.             glVertex3f(vertexes[2][0],vertexes[2][1],vertexes[2][2]);
  1513.             glVertex3f(vertexes[3][0],vertexes[3][1],vertexes[3][2]);
  1514.         glEnd();
  1515.         }
  1516.     }
  1517. }
  1518.  
  1519. void reduceToUnit(GLfloat vector[3])
  1520. {
  1521. float length;
  1522. length = (float)sqrt((vector[0]*vector[0]) + 
  1523. (vector[1]*vector[1]) +
  1524. (vector[2]*vector[2]));
  1525. if(length == 0.0f)
  1526.     length = 1.0f;
  1527.     vector[0] /= length;
  1528.     vector[1] /= length;
  1529.     vector[2] /= length;
  1530. }
  1531. void calcNormal2(VECTOR_STRUCT_TYPE *vertex1, VECTOR_STRUCT_TYPE *vertex2,VECTOR_STRUCT_TYPE *vertex3,GLfloat out[3])
  1532. {
  1533. float v1[3],v2[3];
  1534. static const int x = 0;
  1535. static const int y = 1;
  1536. static const int z = 2;
  1537. v1[x] = vertex1->m_x - vertex2->m_x;
  1538. v1[y] = vertex1->m_y - vertex2->m_y;
  1539. v1[z] = vertex1->m_z - vertex2->m_z;
  1540. v2[x] = vertex2->m_x - vertex3->m_x;
  1541. v2[y] = vertex2->m_y - vertex3->m_y;
  1542. v2[z] = vertex2->m_z - vertex3->m_z;
  1543. /*Cross Product*/
  1544. out[x] = v1[y]*v2[z] - v1[z]*v2[y];
  1545. out[y] = v1[z]*v2[x] - v1[x]*v2[z];
  1546. out[z] = v1[x]*v2[y] - v1[y]*v2[x];
  1547. reduceToUnit(out);
  1548.  
  1549. }
  1550. void calcNormal(GLfloat v[3][3], GLfloat out[3])
  1551. {
  1552. float v1[3],v2[3];
  1553. static const int x = 0;
  1554. static const int y = 1;
  1555. static const int z = 2;
  1556. v1[x] = v[0][x] - v[1][x];
  1557. v1[y] = v[0][y] - v[1][y];
  1558. v1[z] = v[0][z] - v[1][z];
  1559. v2[x] = v[1][x] - v[2][x];
  1560. v2[y] = v[1][y] - v[2][y];
  1561. v2[z] = v[1][z] - v[2][z];
  1562. /*Cross Product*/
  1563. out[x] = v1[y]*v2[z] - v1[z]*v2[y];
  1564. out[y] = v1[z]*v2[x] - v1[x]*v2[z];
  1565. out[z] = v1[x]*v2[y] - v1[y]*v2[x];
  1566. reduceToUnit(out);
  1567. }
  1568.  
  1569. void CMy3DFontView::OnAppAbout() 
  1570. {
  1571.     // TODO: Add your command handler code here
  1572.  
  1573.     CHelp dlg;
  1574.  
  1575.     KillTimer(1);
  1576.     
  1577.     int response=dlg.DoModal();
  1578.  
  1579.     if(response==IDOK)
  1580.     {
  1581.         setSpeed();
  1582.     }
  1583.     Invalidate();
  1584. }
  1585. void generateAsteroid()
  1586. {
  1587.     int i;
  1588.     GLfloat angle;
  1589.     GLfloat x,z;
  1590.     GLfloat velocity;
  1591.  
  1592.     for (i=0; i<ASTEROID_COUNT; i++)
  1593.     {
  1594.         if(objAsteroid[i].m_activeFlag==FALSE)
  1595.         {
  1596.             objAsteroid[i].m_activeFlag=TRUE;
  1597.  
  1598.             if((rand()%2)==0)
  1599.             {
  1600.                 objAsteroid[i].m_x=(GLfloat) (rand()%GRID_SIZE);
  1601.             }
  1602.             else if ((rand()%2)==1)
  1603.             {
  1604.                 objAsteroid[i].m_x=(GLfloat) -(rand()%GRID_SIZE);
  1605.             }
  1606.             else
  1607.             {
  1608.                 objAsteroid[i].m_x=(GLfloat) GRID_SIZE;
  1609.             }
  1610.             objAsteroid[i].m_y=0.0f;
  1611.  
  1612.             if((rand()%2)==0)
  1613.             {
  1614.                 objAsteroid[i].m_z=(GLfloat) GRID_SIZE-20.0f;
  1615.             }
  1616.  
  1617.             else if((rand()%2)==1)
  1618.             {
  1619.                 objAsteroid[i].m_z=(GLfloat) -GRID_SIZE+20.0f;
  1620.             }
  1621.             else
  1622.             {
  1623.                 objAsteroid[i].m_z=(GLfloat) GRID_SIZE-20.0f;
  1624.             }
  1625.  
  1626.             objAsteroid[i].m_colorIndex=rand()%7;
  1627.             objAsteroid[i].m_size=(GLfloat) (rand()%10);
  1628.  
  1629.             angle= (GLfloat) ((rand()%360)/180.0f*3.142f);
  1630.             velocity=(GLfloat) (rand()%20);
  1631.  
  1632.             x= (GLfloat) (velocity*cos(angle));
  1633.             z= (GLfloat) (-velocity*sin(angle));
  1634.  
  1635.             objAsteroid[i].m_angle_radians=angle;
  1636.             objAsteroid[i].m_velocity=velocity;
  1637.             objAsteroid[i].m_radius=objAsteroid[i].m_size/2.0f;
  1638.             objAsteroid[i].m_mass=objAsteroid[i].m_size;
  1639.  
  1640.             objAsteroid[i].dir_x=x;
  1641.             objAsteroid[i].dir_y=0.0f;
  1642.             objAsteroid[i].dir_z=z;
  1643.  
  1644.             objAsteroid[i].m_movement_interval=clock();
  1645.         }//if
  1646.     }//for
  1647. }
  1648. void generateMines()
  1649. {
  1650.     int retval;
  1651.     static long current_time=clock();
  1652.  
  1653.     if ((clock()-current_time)>1000)
  1654.     {
  1655.         current_time=clock();
  1656.         retval=getMineObject();
  1657.         
  1658.         if(retval>-1)
  1659.         {
  1660.             objMineList[retval].m_available_flag=FALSE;
  1661.             objMineList[retval].m_active_flag=TRUE;
  1662.             objMineList[retval].m_x=(GLfloat) GRID_SIZE;
  1663.             objMineList[retval].m_y=0.0f;
  1664.             objMineList[retval].m_z=(GLfloat) -GRID_SIZE;
  1665.             objMineList[retval].m_direction=RIGHT_DIRECTION;
  1666.         }
  1667.     }
  1668.  
  1669. }
  1670. void drawForceMissiles()
  1671. {
  1672.     GLint i;
  1673.     GLfloat x,z;
  1674.     GLfloat distance;
  1675.     GLint retVal;
  1676.  
  1677.     for(i=0; i<NUMBER_OF_MISSILES; i++)
  1678.     {
  1679.         if(shipMissile[i].m_active_flag==TRUE)
  1680.         {
  1681.             shipMissile[i].m_x += (GLfloat) ((10.0f+objForce.m_delta)*cos(shipMissile[i].m_angle_radians));
  1682.             shipMissile[i].m_z += (GLfloat) -((10.0f+objForce.m_delta)*sin(shipMissile[i].m_angle_radians));
  1683.  
  1684.             retVal=checkAsteroidHit(shipMissile[i].m_x,0.0f,shipMissile[i].m_z);
  1685.  
  1686.             if(retVal==1)
  1687.             {
  1688.                 shipMissile[i].m_available_flag=TRUE;
  1689.                 shipMissile[i].m_active_flag=FALSE;
  1690.                 continue;
  1691.             }
  1692.  
  1693.             retVal=checkEnemyHit(shipMissile[i].m_x,5.0f,shipMissile[i].m_z);
  1694.  
  1695.             if (retVal==1)
  1696.             {
  1697.                 shipMissile[i].m_available_flag=TRUE;
  1698.                 shipMissile[i].m_active_flag=FALSE;
  1699.                 break;
  1700.             }
  1701.  
  1702.  
  1703.             retVal=checkMineHit(shipMissile[i].m_x,5.0f,shipMissile[i].m_z);
  1704.             if (retVal==1)
  1705.             {
  1706.                 shipMissile[i].m_available_flag=TRUE;
  1707.                 shipMissile[i].m_active_flag=FALSE;
  1708.                 break;
  1709.             }
  1710.             glPushMatrix();
  1711.                 glTranslatef(shipMissile[i].m_x,shipMissile[i].m_y,shipMissile[i].m_z);
  1712.                 icosahedron();
  1713.                 //Sphere(5,10,10);
  1714.             glPopMatrix();
  1715.  
  1716.             x=objForce.m_xPos-shipMissile[i].m_x;
  1717.             z=objForce.m_zPos-shipMissile[i].m_z;
  1718.  
  1719.             distance=(GLfloat) sqrt(x*x+shipMissile[i].m_y*shipMissile[i].m_y+z*z);
  1720.             if (distance>200)
  1721.             {
  1722.                 shipMissile[i].m_available_flag=TRUE;
  1723.                 shipMissile[i].m_active_flag=FALSE;
  1724.             }
  1725.         }
  1726.     }
  1727.  
  1728.     if(objForce.m_hit==1)
  1729.     {
  1730.         objForce.m_hit=0;
  1731.  
  1732.         EnemyEngine[0].x=(GLfloat) (rand()%300);
  1733.         EnemyEngine[0].z=(GLfloat) (rand()%300);
  1734.         EnemyEngine[0].m_angle_radians=1.57f;
  1735.         EnemyEngine[0].m_cpu_clicks=clock();
  1736.         EnemyEngine[0].m_sleep=TRUE;
  1737.         objForce.m_score+=100;
  1738.     }
  1739.  
  1740. }
  1741.  
  1742. void drawForceAsteroids()
  1743. {
  1744.     GLint i;
  1745.     GLfloat distance;
  1746.     GLfloat x,y,z;
  1747.     GLfloat asteroid1_x,asteroid1_y,asteroid1_z;
  1748.     GLfloat asteroid1_radius;
  1749.     GLfloat angle,velocity;
  1750.     int other_index;
  1751.  
  1752.     for(i=0; i<ASTEROID_COUNT; i++)
  1753.     {
  1754.         if(objAsteroid[i].m_activeFlag==TRUE)
  1755.         {
  1756.             if ((clock()-objAsteroid[i].m_movement_interval)>2*CLOCKS_PER_SEC)
  1757.             {
  1758.                 asteroid1_x=objAsteroid[i].m_x;
  1759.                 asteroid1_y=objAsteroid[i].m_y;
  1760.                 asteroid1_z=objAsteroid[i].m_z;
  1761.                 asteroid1_radius=objAsteroid[i].m_radius;
  1762.  
  1763.                 if ((asteroid1_x+asteroid1_radius)>GRID_SIZE)
  1764.                 {
  1765.                     objAsteroid[i].dir_x*=-1.0f;
  1766.                 }
  1767.                 else if ((asteroid1_x-asteroid1_radius)<-GRID_SIZE)
  1768.                 {
  1769.                     objAsteroid[i].dir_x*=-1.0f;
  1770.                 }
  1771.  
  1772.                 if ((asteroid1_z+asteroid1_radius)>GRID_SIZE)
  1773.                 {
  1774.                     objAsteroid[i].dir_z*=-1.0f;
  1775.                 }
  1776.                 else if ((asteroid1_z-asteroid1_radius)<-GRID_SIZE)
  1777.                 {
  1778.                     objAsteroid[i].dir_z*=-1.0f;
  1779.                 }
  1780.  
  1781.                 x=asteroid1_x-objForce.m_xPos;
  1782.                 y=asteroid1_y-objForce.m_yPos;
  1783.                 z=asteroid1_z-objForce.m_zPos;
  1784.                 
  1785.                 distance=(GLfloat) sqrt(x*x+y*y+z*z);
  1786.  
  1787.                 //asteroid hit the ship
  1788.                 if(distance<30)
  1789.                 {
  1790.                     objForce.m_shield--;
  1791.  
  1792.                     angle=objAsteroid[i].m_angle_radians+3.142f;
  1793.                     velocity=objAsteroid[i].m_velocity;
  1794.  
  1795.                     objAsteroid[i].dir_x= (GLfloat) (velocity*cos(angle));
  1796.                     objAsteroid[i].dir_z= (GLfloat) (-velocity*sin(angle));
  1797.  
  1798.                 }
  1799.  
  1800.                 //asteroid hit the enemy
  1801.                 x=asteroid1_x-EnemyEngine[0].x;
  1802.                 y=asteroid1_y-EnemyEngine[0].y;
  1803.                 z=asteroid1_z-EnemyEngine[0].z;
  1804.                 
  1805.                 distance=(GLfloat) sqrt(x*x+y*y+z*z);
  1806.  
  1807.                 if(distance<30)
  1808.                 {
  1809.                     objForce.m_shield--;
  1810.  
  1811.                     angle=objAsteroid[i].m_angle_radians+3.142f;
  1812.                     velocity=objAsteroid[i].m_velocity;
  1813.  
  1814.                     objAsteroid[i].dir_x= (GLfloat) (velocity*cos(angle));
  1815.                     objAsteroid[i].dir_z= (GLfloat) (-velocity*sin(angle));
  1816.  
  1817.                 }
  1818.  
  1819.                 
  1820.                 other_index=checkAsteroidCollision(i,asteroid1_x,asteroid1_y,asteroid1_z,asteroid1_radius);
  1821.  
  1822.                 if (other_index!=-1)
  1823.                 {
  1824.                     collision(i,other_index);
  1825.                     //displace beyond the radius
  1826.                 
  1827.                     //Asteroid 1
  1828.                     x= (GLfloat) (objAsteroid[i].m_radius*cos(objAsteroid[i].m_radius));
  1829.                     z= (GLfloat) (-objAsteroid[i].m_radius*sin(objAsteroid[i].m_radius));
  1830.                     
  1831.                     objAsteroid[i].m_x+=x;
  1832.                     objAsteroid[i].m_z+=z;
  1833.                     //Asteroid 2
  1834.                     x= (GLfloat) (objAsteroid[other_index].m_radius*cos(objAsteroid[other_index].m_radius));
  1835.                     z= (GLfloat) (-objAsteroid[other_index].m_radius*sin(objAsteroid[other_index].m_radius));
  1836.                     
  1837.                     objAsteroid[other_index].m_x+=x;
  1838.                     objAsteroid[other_index].m_z+=z;
  1839.                 }
  1840.                 objAsteroid[i].m_x+=objAsteroid[i].dir_x;
  1841.                 objAsteroid[i].m_y=0.0f;
  1842.                 objAsteroid[i].m_z+=objAsteroid[i].dir_z;
  1843.             }
  1844.             setSpecularMaterialColor(1.0f,1.0f,1.0f,0.6f);
  1845.             setMaterialShininess(128.0f);
  1846.             setAmbientMaterialColor(0.2f,0.0f,0.0f,0.6f);
  1847.  
  1848.             switch(objAsteroid[i].m_colorIndex)
  1849.             {
  1850.             case 7:
  1851.                 copperMaterial();
  1852.                 break;
  1853.             case 6:
  1854.                 brassMaterial();
  1855.                 break;
  1856.             case 5:
  1857.                 goldMaterial();
  1858.                 break;
  1859.             case 4:  //blue
  1860.                 setDiffuseMaterialColor(0.0f,0.0f,0.78f,1.0f);
  1861.                 break;
  1862.             case 3:  //green
  1863.                 setDiffuseMaterialColor(0.0f,0.78f,0.0f,1.0f);
  1864.                 break;            
  1865.             case 2:  //red
  1866.                 setDiffuseMaterialColor(0.78f,0.0f,0.0f,1.0f);
  1867.                 break;            
  1868.             case 1:  //yellow
  1869.                 setDiffuseMaterialColor(0.78f,0.78f,0.0f,1.0f);
  1870.                 break;            
  1871.             }
  1872.             glPushMatrix();
  1873.                 glTranslatef(objAsteroid[i].m_x,objAsteroid[i].m_y,objAsteroid[i].m_z);
  1874.                 glScalef(objAsteroid[i].m_size,objAsteroid[i].m_size,objAsteroid[i].m_size);
  1875.                 sphere(1.0f);
  1876.             glPopMatrix();
  1877.         }
  1878.     }
  1879.  
  1880. }
  1881. int checkAsteroidCollision(int exclude_index, GLfloat asteroid1_x,GLfloat asteroid1_y,GLfloat asteroid1_z,GLfloat asteroid1_radius)
  1882. {
  1883. GLfloat asteroid2_x,asteroid2_y,asteroid2_z;
  1884. GLfloat x,y,z;
  1885. GLfloat distance;
  1886. GLfloat radius_threshold;
  1887. int i;
  1888.  
  1889.     for(i=0; i<ASTEROID_COUNT; i++)
  1890.     {
  1891.         if( 
  1892.             (objAsteroid[i].m_activeFlag==TRUE) &&
  1893.             (i != exclude_index)
  1894.         )
  1895.         {
  1896.             asteroid2_x=objAsteroid[i].m_x;
  1897.             asteroid2_y=objAsteroid[i].m_y;
  1898.             asteroid2_z=objAsteroid[i].m_z;
  1899.  
  1900.             x=asteroid2_x-asteroid1_x;
  1901.             y=asteroid2_y-asteroid1_y;
  1902.             z=asteroid2_z-asteroid1_z;
  1903.  
  1904.             radius_threshold=objAsteroid[i].m_radius+asteroid1_radius;
  1905.  
  1906.             distance=(GLfloat) sqrt(x*x+y*y+z*z);
  1907.  
  1908.             if(distance<radius_threshold)
  1909.             {
  1910.                 return(i);
  1911.             }
  1912.         }
  1913.     }
  1914.     return(-1);
  1915.  
  1916. }
  1917. void drawTieFighter()
  1918. {
  1919.     float tiefighterDrawingCoordinates[200][3];
  1920.     int i;
  1921.     float v[3][3];
  1922.     float normal[3];    
  1923.     float xa,xb,xc,xd,xe,xf,xg,xh,xi,xj;
  1924.     float ya,yb,yc,yd,ye,yf,yg;
  1925.     float za,zb,zc,zd,ze,zf,zg;
  1926.     float scale;
  1927.  
  1928.     scale=10.0f;
  1929.  
  1930.     xa = -55.0f/scale;
  1931.     xb = -30.0f/scale;
  1932.     xc = 30.0f/scale;
  1933.     xd = 55.0f/scale;
  1934.     xe = -5.0f/scale;
  1935.     xf = 0.0f/scale;
  1936.     xg = 5.0f/scale;
  1937.     xh = -40.0f/scale;
  1938.     xi = 40.0f/scale;
  1939.     xj = 0.0f;
  1940.  
  1941.     ya = 70.0f/scale;
  1942.     yb = 0.0f;
  1943.     yc = -70.0f/scale;
  1944.     yd = 7.0f/scale; 
  1945.     ye = -7.0f/scale;
  1946.     yf = 40.0f/scale;
  1947.     yg = -40.0f/scale; 
  1948.     
  1949.     za = 80.0f/scale; 
  1950.     zb = 15.0f/scale;
  1951.     zc = -15.0f/scale;
  1952.     zd = -80.0f/scale; 
  1953.     ze = 40.0f/scale;
  1954.     zf = 0.0f/scale; 
  1955.     zg = -40.0f/scale;
  1956.  
  1957.     //Cockpit
  1958.     tiefighterDrawingCoordinates[0][0] = xj;
  1959.     tiefighterDrawingCoordinates[0][1] = yf;
  1960.     tiefighterDrawingCoordinates[0][2] = zf;
  1961.     tiefighterDrawingCoordinates[1][0] = xj;
  1962.     tiefighterDrawingCoordinates[1][1] = yb;
  1963.     tiefighterDrawingCoordinates[1][2] = ze;
  1964.     tiefighterDrawingCoordinates[2][0] = xi;
  1965.     tiefighterDrawingCoordinates[2][1] = yb;
  1966.     tiefighterDrawingCoordinates[2][2] = zf;
  1967.  
  1968.     tiefighterDrawingCoordinates[3][0] = xj;
  1969.     tiefighterDrawingCoordinates[3][1] = yb;
  1970.     tiefighterDrawingCoordinates[3][2] = zg;
  1971.     tiefighterDrawingCoordinates[4][0] = xj;
  1972.     tiefighterDrawingCoordinates[4][1] = yf;
  1973.     tiefighterDrawingCoordinates[4][2] = zf;
  1974.     tiefighterDrawingCoordinates[5][0] = xi;
  1975.     tiefighterDrawingCoordinates[5][1] = yb;
  1976.     tiefighterDrawingCoordinates[5][2] = zf;
  1977.  
  1978.     tiefighterDrawingCoordinates[6][0] = xi;
  1979.     tiefighterDrawingCoordinates[6][1] = yb;
  1980.     tiefighterDrawingCoordinates[6][2] = zf;
  1981.     tiefighterDrawingCoordinates[7][0] = xj;
  1982.     tiefighterDrawingCoordinates[7][1] = yb;
  1983.     tiefighterDrawingCoordinates[7][2] = ze;
  1984.     tiefighterDrawingCoordinates[8][0] = xj;
  1985.     tiefighterDrawingCoordinates[8][1] = yg;
  1986.     tiefighterDrawingCoordinates[8][2] = zf;
  1987.  
  1988.     tiefighterDrawingCoordinates[9][0] = xj;
  1989.     tiefighterDrawingCoordinates[9][1] = yb;
  1990.     tiefighterDrawingCoordinates[9][2] = zg;
  1991.     tiefighterDrawingCoordinates[10][0] = xi;
  1992.     tiefighterDrawingCoordinates[10][1] = yb;
  1993.     tiefighterDrawingCoordinates[10][2] = zf;
  1994.     tiefighterDrawingCoordinates[11][0] = xj;
  1995.     tiefighterDrawingCoordinates[11][1] = yg;
  1996.     tiefighterDrawingCoordinates[11][2] = zf;
  1997.  
  1998.     tiefighterDrawingCoordinates[12][0] = xh;
  1999.     tiefighterDrawingCoordinates[12][1] = yb;
  2000.     tiefighterDrawingCoordinates[12][2] = zf;
  2001.     tiefighterDrawingCoordinates[13][0] = xj;
  2002.     tiefighterDrawingCoordinates[13][1] = yf;
  2003.     tiefighterDrawingCoordinates[13][2] = zf;
  2004.     tiefighterDrawingCoordinates[14][0] = xj;
  2005.     tiefighterDrawingCoordinates[14][1] = yb;
  2006.     tiefighterDrawingCoordinates[14][2] = zg;
  2007.  
  2008.     tiefighterDrawingCoordinates[15][0] = xj;
  2009.     tiefighterDrawingCoordinates[15][1] = yf;
  2010.     tiefighterDrawingCoordinates[15][2] = zf;
  2011.     tiefighterDrawingCoordinates[16][0] = xh;
  2012.     tiefighterDrawingCoordinates[16][1] = yb;
  2013.     tiefighterDrawingCoordinates[16][2] = zf;
  2014.     tiefighterDrawingCoordinates[17][0] = xj;
  2015.     tiefighterDrawingCoordinates[17][1] = yb;
  2016.     tiefighterDrawingCoordinates[17][2] = ze;
  2017.  
  2018.     tiefighterDrawingCoordinates[18][0] = xh;
  2019.     tiefighterDrawingCoordinates[18][1] = yb;
  2020.     tiefighterDrawingCoordinates[18][2] = zf;
  2021.     tiefighterDrawingCoordinates[19][0] = xj;
  2022.     tiefighterDrawingCoordinates[19][1] = yg;
  2023.     tiefighterDrawingCoordinates[19][2] = zf;
  2024.     tiefighterDrawingCoordinates[20][0] = xj;
  2025.     tiefighterDrawingCoordinates[20][1] = yb;
  2026.     tiefighterDrawingCoordinates[20][2] = ze;
  2027.  
  2028.     tiefighterDrawingCoordinates[21][0] = xh;
  2029.     tiefighterDrawingCoordinates[21][1] = yb;
  2030.     tiefighterDrawingCoordinates[21][2] = zf;
  2031.     tiefighterDrawingCoordinates[22][0] = xj;
  2032.     tiefighterDrawingCoordinates[22][1] = yb;
  2033.     tiefighterDrawingCoordinates[22][2] = zg;
  2034.     tiefighterDrawingCoordinates[23][0] = xj;
  2035.     tiefighterDrawingCoordinates[23][1] = yg;
  2036.     tiefighterDrawingCoordinates[23][2] = zf;
  2037.  
  2038.     //left strut
  2039.     tiefighterDrawingCoordinates[24][0] = xj;
  2040.     tiefighterDrawingCoordinates[24][1] = yb;
  2041.     tiefighterDrawingCoordinates[24][2] = zb;
  2042.     tiefighterDrawingCoordinates[25][0] = xf;
  2043.     tiefighterDrawingCoordinates[25][1] = yd;
  2044.     tiefighterDrawingCoordinates[25][2] = za;
  2045.     tiefighterDrawingCoordinates[26][0] = xg;
  2046.     tiefighterDrawingCoordinates[26][1] = ye;
  2047.     tiefighterDrawingCoordinates[26][2] = za;
  2048.  
  2049.     tiefighterDrawingCoordinates[27][0] = xj;
  2050.     tiefighterDrawingCoordinates[27][1] = yb;
  2051.     tiefighterDrawingCoordinates[27][2] = zb;
  2052.     tiefighterDrawingCoordinates[28][0] = xe;
  2053.     tiefighterDrawingCoordinates[28][1] = ye;
  2054.     tiefighterDrawingCoordinates[28][2] = za;
  2055.     tiefighterDrawingCoordinates[29][0] = xf;
  2056.     tiefighterDrawingCoordinates[29][1] = yd;
  2057.     tiefighterDrawingCoordinates[29][2] = za;
  2058.  
  2059.     tiefighterDrawingCoordinates[30][0] = xg;
  2060.     tiefighterDrawingCoordinates[30][1] = ye;
  2061.     tiefighterDrawingCoordinates[30][2] = za;
  2062.     tiefighterDrawingCoordinates[31][0] = xe;
  2063.     tiefighterDrawingCoordinates[31][1] = ye;
  2064.     tiefighterDrawingCoordinates[31][2] = za;
  2065.     tiefighterDrawingCoordinates[32][0] = xj;
  2066.     tiefighterDrawingCoordinates[32][1] = yb;
  2067.     tiefighterDrawingCoordinates[32][2] = zb;
  2068.  
  2069.     //right strut
  2070.     tiefighterDrawingCoordinates[33][0] = xe;
  2071.     tiefighterDrawingCoordinates[33][1] = ye;
  2072.     tiefighterDrawingCoordinates[33][2] = zd;
  2073.     tiefighterDrawingCoordinates[34][0] = xj;
  2074.     tiefighterDrawingCoordinates[34][1] = yb;
  2075.     tiefighterDrawingCoordinates[34][2] = zc;
  2076.     tiefighterDrawingCoordinates[35][0] = xf;
  2077.     tiefighterDrawingCoordinates[35][1] = yd;
  2078.     tiefighterDrawingCoordinates[35][2] = zd;
  2079.  
  2080.     tiefighterDrawingCoordinates[36][0] = xf;
  2081.     tiefighterDrawingCoordinates[36][1] = yd;
  2082.     tiefighterDrawingCoordinates[36][2] = zd;
  2083.     tiefighterDrawingCoordinates[37][0] = xj;
  2084.     tiefighterDrawingCoordinates[37][1] = yb;
  2085.     tiefighterDrawingCoordinates[37][2] = zc;
  2086.     tiefighterDrawingCoordinates[38][0] = xg;
  2087.     tiefighterDrawingCoordinates[38][1] = ye;
  2088.     tiefighterDrawingCoordinates[38][2] = zd;
  2089.  
  2090.     tiefighterDrawingCoordinates[39][0] = xg;
  2091.     tiefighterDrawingCoordinates[39][1] = ye;
  2092.     tiefighterDrawingCoordinates[39][2] = zd;
  2093.     tiefighterDrawingCoordinates[40][0] = xj;
  2094.     tiefighterDrawingCoordinates[40][1] = yb;
  2095.     tiefighterDrawingCoordinates[40][2] = zc;
  2096.     tiefighterDrawingCoordinates[41][0] = xe;
  2097.     tiefighterDrawingCoordinates[41][1] = ye;
  2098.     tiefighterDrawingCoordinates[41][2] = zd;
  2099.  
  2100.     //left "wing"
  2101.     tiefighterDrawingCoordinates[42][0] = xb;
  2102.     tiefighterDrawingCoordinates[42][1] = ya;
  2103.     tiefighterDrawingCoordinates[42][2] = za;
  2104.     tiefighterDrawingCoordinates[43][0] = xa;
  2105.     tiefighterDrawingCoordinates[43][1] = yb;
  2106.     tiefighterDrawingCoordinates[43][2] = za;
  2107.     tiefighterDrawingCoordinates[44][0] = xb;
  2108.     tiefighterDrawingCoordinates[44][1] = yc;
  2109.     tiefighterDrawingCoordinates[44][2] = za;
  2110.  
  2111.     tiefighterDrawingCoordinates[45][0] = xb;
  2112.     tiefighterDrawingCoordinates[45][1] = yc;
  2113.     tiefighterDrawingCoordinates[45][2] = za;
  2114.     tiefighterDrawingCoordinates[46][0] = xc;
  2115.     tiefighterDrawingCoordinates[46][1] = yc;
  2116.     tiefighterDrawingCoordinates[46][2] = za;
  2117.     tiefighterDrawingCoordinates[47][0] = xb;
  2118.     tiefighterDrawingCoordinates[47][1] = ya;
  2119.     tiefighterDrawingCoordinates[47][2] = za;
  2120.  
  2121.     tiefighterDrawingCoordinates[48][0] = xb;
  2122.     tiefighterDrawingCoordinates[48][1] = ya;
  2123.     tiefighterDrawingCoordinates[48][2] = za;
  2124.     tiefighterDrawingCoordinates[49][0] = xc;
  2125.     tiefighterDrawingCoordinates[49][1] = yc;
  2126.     tiefighterDrawingCoordinates[49][2] = za;
  2127.     tiefighterDrawingCoordinates[50][0] = xc;
  2128.     tiefighterDrawingCoordinates[50][1] = ya;
  2129.     tiefighterDrawingCoordinates[50][2] = za;
  2130.  
  2131.     tiefighterDrawingCoordinates[51][0] = xc;
  2132.     tiefighterDrawingCoordinates[51][1] = ya;
  2133.     tiefighterDrawingCoordinates[51][2] = za;
  2134.     tiefighterDrawingCoordinates[52][0] = xc;
  2135.     tiefighterDrawingCoordinates[52][1] = yc;
  2136.     tiefighterDrawingCoordinates[52][2] = za;
  2137.     tiefighterDrawingCoordinates[53][0] = xd;
  2138.     tiefighterDrawingCoordinates[53][1] = yb;
  2139.     tiefighterDrawingCoordinates[53][2] = za;
  2140.  
  2141.     //Must redraw left "wing" due to rear face culling.
  2142.     tiefighterDrawingCoordinates[54][0] = xa;
  2143.     tiefighterDrawingCoordinates[54][1] = yb;
  2144.     tiefighterDrawingCoordinates[54][2] = za;
  2145.     tiefighterDrawingCoordinates[55][0] = xb;
  2146.     tiefighterDrawingCoordinates[55][1] = ya;
  2147.     tiefighterDrawingCoordinates[55][2] = za;
  2148.     tiefighterDrawingCoordinates[56][0] = xb;
  2149.     tiefighterDrawingCoordinates[56][1] = yc;
  2150.     tiefighterDrawingCoordinates[56][2] = za;
  2151.  
  2152.     tiefighterDrawingCoordinates[57][0] = xc;
  2153.     tiefighterDrawingCoordinates[57][1] = yc;
  2154.     tiefighterDrawingCoordinates[57][2] = za;
  2155.     tiefighterDrawingCoordinates[58][0] = xb;
  2156.     tiefighterDrawingCoordinates[58][1] = yc;
  2157.     tiefighterDrawingCoordinates[58][2] = za;
  2158.     tiefighterDrawingCoordinates[59][0] = xb;
  2159.     tiefighterDrawingCoordinates[59][1] = ya;
  2160.     tiefighterDrawingCoordinates[59][2] = za;
  2161.  
  2162.     tiefighterDrawingCoordinates[60][0] = xc;
  2163.     tiefighterDrawingCoordinates[60][1] = yc;
  2164.     tiefighterDrawingCoordinates[60][2] = za;
  2165.     tiefighterDrawingCoordinates[61][0] = xb;
  2166.     tiefighterDrawingCoordinates[61][1] = ya;
  2167.     tiefighterDrawingCoordinates[61][2] = za;
  2168.     tiefighterDrawingCoordinates[62][0] = xc;
  2169.     tiefighterDrawingCoordinates[62][1] = ya;
  2170.     tiefighterDrawingCoordinates[62][2] = za;
  2171.  
  2172.     tiefighterDrawingCoordinates[63][0] = xc;
  2173.     tiefighterDrawingCoordinates[63][1] = yc;
  2174.     tiefighterDrawingCoordinates[63][2] = za;
  2175.     tiefighterDrawingCoordinates[64][0] = xc;
  2176.     tiefighterDrawingCoordinates[64][1] = ya;
  2177.     tiefighterDrawingCoordinates[64][2] = za;
  2178.     tiefighterDrawingCoordinates[65][0] = xd;
  2179.     tiefighterDrawingCoordinates[65][1] = yb;
  2180.     tiefighterDrawingCoordinates[65][2] = za;
  2181.  
  2182.     //right "wing"
  2183.     tiefighterDrawingCoordinates[66][0] = xb;
  2184.     tiefighterDrawingCoordinates[66][1] = ya;
  2185.     tiefighterDrawingCoordinates[66][2] = zd;
  2186.     tiefighterDrawingCoordinates[67][0] = xa;
  2187.     tiefighterDrawingCoordinates[67][1] = yb;
  2188.     tiefighterDrawingCoordinates[67][2] = zd;
  2189.     tiefighterDrawingCoordinates[68][0] = xb;
  2190.     tiefighterDrawingCoordinates[68][1] = yc;
  2191.     tiefighterDrawingCoordinates[68][2] = zd;
  2192.  
  2193.     tiefighterDrawingCoordinates[69][0] = xb;
  2194.     tiefighterDrawingCoordinates[69][1] = yc;
  2195.     tiefighterDrawingCoordinates[69][2] = zd;
  2196.     tiefighterDrawingCoordinates[70][0] = xc;
  2197.     tiefighterDrawingCoordinates[70][1] = ya;
  2198.     tiefighterDrawingCoordinates[70][2] = zd;
  2199.     tiefighterDrawingCoordinates[71][0] = xb;
  2200.     tiefighterDrawingCoordinates[71][1] = ya;
  2201.     tiefighterDrawingCoordinates[71][2] = zd;
  2202.  
  2203.     tiefighterDrawingCoordinates[72][0] = xc;
  2204.     tiefighterDrawingCoordinates[72][1] = ya;
  2205.     tiefighterDrawingCoordinates[72][2] = zd;
  2206.     tiefighterDrawingCoordinates[73][0] = xb;
  2207.     tiefighterDrawingCoordinates[73][1] = yc;
  2208.     tiefighterDrawingCoordinates[73][2] = zd;
  2209.     tiefighterDrawingCoordinates[74][0] = xc;
  2210.     tiefighterDrawingCoordinates[74][1] = yc;
  2211.     tiefighterDrawingCoordinates[74][2] = zd;
  2212.  
  2213.     tiefighterDrawingCoordinates[75][0] = xc;
  2214.     tiefighterDrawingCoordinates[75][1] = yc;
  2215.     tiefighterDrawingCoordinates[75][2] = zd;
  2216.     tiefighterDrawingCoordinates[76][0] = xd;
  2217.     tiefighterDrawingCoordinates[76][1] = yb;
  2218.     tiefighterDrawingCoordinates[76][2] = zd;
  2219.     tiefighterDrawingCoordinates[77][0] = xc;
  2220.     tiefighterDrawingCoordinates[77][1] = ya;
  2221.     tiefighterDrawingCoordinates[77][2] = zd;
  2222.  
  2223.     //Must redraw the right "wing" due to rear face culling
  2224.     tiefighterDrawingCoordinates[78][0] = xa;
  2225.     tiefighterDrawingCoordinates[78][1] = yb;
  2226.     tiefighterDrawingCoordinates[78][2] = zd;
  2227.     tiefighterDrawingCoordinates[79][0] = xb;
  2228.     tiefighterDrawingCoordinates[79][1] = ya;
  2229.     tiefighterDrawingCoordinates[79][2] = zd;
  2230.     tiefighterDrawingCoordinates[80][0] = xb;
  2231.     tiefighterDrawingCoordinates[80][1] = yc;
  2232.     tiefighterDrawingCoordinates[80][2] = zd;
  2233.  
  2234.     tiefighterDrawingCoordinates[81][0] = xc;
  2235.     tiefighterDrawingCoordinates[81][1] = ya;
  2236.     tiefighterDrawingCoordinates[81][2] = zd;
  2237.     tiefighterDrawingCoordinates[82][0] = xb;
  2238.     tiefighterDrawingCoordinates[82][1] = yc;
  2239.     tiefighterDrawingCoordinates[82][2] = zd;
  2240.     tiefighterDrawingCoordinates[83][0] = xb;
  2241.     tiefighterDrawingCoordinates[83][1] = ya;
  2242.     tiefighterDrawingCoordinates[83][2] = zd;
  2243.  
  2244.     tiefighterDrawingCoordinates[84][0] = xb;
  2245.     tiefighterDrawingCoordinates[84][1] = yc;
  2246.     tiefighterDrawingCoordinates[84][2] = zd;
  2247.     tiefighterDrawingCoordinates[85][0] = xc;
  2248.     tiefighterDrawingCoordinates[85][1] = ya;
  2249.     tiefighterDrawingCoordinates[85][2] = zd;
  2250.     tiefighterDrawingCoordinates[86][0] = xc;
  2251.     tiefighterDrawingCoordinates[86][1] = yc;
  2252.     tiefighterDrawingCoordinates[86][2] = zd;
  2253.  
  2254.     tiefighterDrawingCoordinates[87][0] = xd;
  2255.     tiefighterDrawingCoordinates[87][1] = yb;
  2256.     tiefighterDrawingCoordinates[87][2] = zd;
  2257.     tiefighterDrawingCoordinates[88][0] = xc;
  2258.     tiefighterDrawingCoordinates[88][1] = yc;
  2259.     tiefighterDrawingCoordinates[88][2] = zd;
  2260.     tiefighterDrawingCoordinates[89][0] = xc;
  2261.     tiefighterDrawingCoordinates[89][1] = ya;
  2262.     tiefighterDrawingCoordinates[89][2] = zd;
  2263.  
  2264.     for (i = 0; i < 30; i++)
  2265.     {
  2266.         v[0][0] = tiefighterDrawingCoordinates[i*3][0];
  2267.         v[0][1] = tiefighterDrawingCoordinates[i*3][1];
  2268.         v[0][2] = tiefighterDrawingCoordinates[i*3][2];
  2269.         v[1][0] = tiefighterDrawingCoordinates[(i*3)+1][0];
  2270.         v[1][1] = tiefighterDrawingCoordinates[(i*3)+1][1];
  2271.         v[1][2] = tiefighterDrawingCoordinates[(i*3)+1][2];
  2272.         v[2][0] = tiefighterDrawingCoordinates[(i*3)+2][0];
  2273.         v[2][1] = tiefighterDrawingCoordinates[(i*3)+2][1];
  2274.         v[2][2] = tiefighterDrawingCoordinates[(i*3)+2][2];    
  2275.  
  2276.         calcNormal(v,normal);
  2277.         glBegin(GL_TRIANGLES);
  2278.             glNormal3fv(normal);    
  2279.             glVertex3fv(v[0]);
  2280.             glVertex3fv(v[1]);
  2281.             glVertex3fv(v[2]);
  2282.         glEnd();
  2283.     } 
  2284.  
  2285. }
  2286. int checkAsteroidHit(GLfloat x,GLfloat y,GLfloat z)
  2287. {
  2288. int i;
  2289. int retval;
  2290. GLfloat asteroid_x,asteroid_y,asteroid_z;
  2291. GLfloat vector_x,vector_y,vector_z;
  2292. GLfloat distance;
  2293. GLfloat size;
  2294. int index;
  2295.  
  2296.     retval=0;
  2297.  
  2298.     for(i=0; i<ASTEROID_COUNT; i++)
  2299.     {
  2300.         asteroid_x=objAsteroid[i].m_x;
  2301.         asteroid_y=objAsteroid[i].m_y;
  2302.         asteroid_z=objAsteroid[i].m_z;
  2303.     
  2304.         vector_x=asteroid_x-x;
  2305.         vector_y=asteroid_y-y;
  2306.         vector_z=asteroid_z-z;
  2307.  
  2308.         distance=(GLfloat) sqrt(vector_x*vector_x+vector_y*vector_y+vector_z*vector_z);
  2309.  
  2310.         if(distance<=10)
  2311.         {
  2312.             objAsteroid[i].m_activeFlag=FALSE;
  2313.             size=objAsteroid[i].m_size;
  2314.             
  2315.             if(size>1 && size<5)
  2316.             {
  2317.                 objForce.m_score+=10;
  2318.             }
  2319.             else if(size>5 && size<10)
  2320.             {
  2321.                 objForce.m_score+=5;
  2322.             }
  2323.             else
  2324.             {
  2325.                 objForce.m_score+=1;
  2326.             }
  2327.  
  2328.             index=getAvailableExplosion();
  2329.             if(index>-1)
  2330.             {
  2331.                 objExplosion[index].x=asteroid_x;
  2332.                 objExplosion[index].y=asteroid_y;
  2333.                 objExplosion[index].z=asteroid_z;
  2334.                 objExplosion[index].m_cpu_seconds=clock();
  2335.                 objExplosion[index].type=SPHERE_TYPE;
  2336.             }
  2337.  
  2338.             //sound("hit.wav");
  2339.              retval=1;
  2340.             return(retval);
  2341.         }
  2342.     }
  2343.     return(retval);
  2344. }
  2345. int checkMineHit(GLfloat x,GLfloat y,GLfloat z)
  2346. {
  2347. int i;
  2348. int retval;
  2349. GLfloat mine_x,mine_y,mine_z;
  2350. GLfloat vector_x,vector_y,vector_z;
  2351. GLfloat distance;
  2352. int index;
  2353.  
  2354.     retval=0;
  2355.  
  2356.     for(i=0; i<MINE_LIST_SIZE; i++)
  2357.     {
  2358.         mine_x=objMineList[i].m_x;
  2359.         mine_y=objMineList[i].m_y;
  2360.         mine_z=objMineList[i].m_z;
  2361.     
  2362.         vector_x=mine_x-x;
  2363.         vector_y=mine_y-y;
  2364.         vector_z=mine_z-z;
  2365.  
  2366.         distance=(GLfloat) sqrt(vector_x*vector_x+vector_y*vector_y+vector_z*vector_z);
  2367.  
  2368.         if(distance<=10)
  2369.         {
  2370.             objMineList[i].m_active_flag=FALSE;
  2371.             objMineList[i].m_available_flag=TRUE;
  2372.  
  2373.             objForce.m_score+=5;
  2374.  
  2375.             index=getAvailableExplosion();
  2376.             if(index>-1)
  2377.             {
  2378.                 objExplosion[index].x=mine_x;
  2379.                 objExplosion[index].y=mine_y;
  2380.                 objExplosion[index].z=mine_z;
  2381.                 objExplosion[index].m_cpu_seconds=clock();
  2382.                 objExplosion[index].type=SPHERE_TYPE;
  2383.             }
  2384.  
  2385.             //sound("hit.wav");
  2386.              retval=1;
  2387.             return(retval);
  2388.         }
  2389.     }
  2390.     return(retval);
  2391. }
  2392.  
  2393. void fireForceBall(GLfloat Yaw,GLfloat Pitch,GLfloat Vo)
  2394. {
  2395.     GLint i;
  2396.  
  2397.     i=getAvailableMissile();
  2398.  
  2399.     if(i>-1)
  2400.     {
  2401.         shipMissile[i].m_x=objForce.m_xPos;
  2402.         shipMissile[i].m_y=objForce.m_yPos;
  2403.         shipMissile[i].m_z=objForce.m_zPos;
  2404.         shipMissile[i].m_Vo=Vo;
  2405.         shipMissile[i].m_angle_radians=objForce.m_angle_radians;
  2406.         shipMissile[i].m_available_flag=FALSE;
  2407.         shipMissile[i].m_active_flag=TRUE;
  2408.     }
  2409. }
  2410.  
  2411. void moveForce()
  2412. {
  2413.     GLfloat xDelta,zDelta;
  2414.     GLfloat light0pos[4];
  2415.     GLfloat distance;
  2416.     GLfloat x,y,z;
  2417.     GLfloat x2,y2,z2;
  2418.     
  2419.     checkBonusCollision();
  2420.  
  2421.     xDelta = (GLfloat) (objForce.m_delta*cos(objForce.m_angle_radians));
  2422.     zDelta = (GLfloat) (-objForce.m_delta*sin(objForce.m_angle_radians));
  2423.  
  2424.     x=objForce.m_xPos+xDelta;
  2425.     y=objForce.m_yPos;
  2426.     z=objForce.m_zPos+zDelta;
  2427.  
  2428.     x2=EnemyEngine[0].x;
  2429.     y2=EnemyEngine[0].y;
  2430.     z2=EnemyEngine[0].z;
  2431.  
  2432.     distance=(GLfloat) sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2)+(z-z2)*(z-z2));
  2433.  
  2434.     if(distance<10)
  2435.     {
  2436.         return;
  2437.     }
  2438.  
  2439.     xDelta = (GLfloat) (objForce.m_delta*cos(objForce.m_angle_radians));
  2440.     zDelta = (GLfloat) (-objForce.m_delta*sin(objForce.m_angle_radians));
  2441.  
  2442.     objForce.m_xPos += (float)xDelta;
  2443.     objForce.m_zPos += (float)zDelta;
  2444.  
  2445.     if(objForce.m_xPos > GRID_SIZE)
  2446.         objForce.m_xPos = (float) GRID_SIZE;
  2447.  
  2448.     if(objForce.m_xPos < -GRID_SIZE)
  2449.         objForce.m_xPos = (float) -GRID_SIZE;
  2450.     
  2451.     if(objForce.m_zPos > GRID_SIZE)
  2452.        objForce.m_zPos = (float) GRID_SIZE;
  2453.  
  2454.     if(objForce.m_zPos < -GRID_SIZE)
  2455.        objForce.m_zPos = (float) -GRID_SIZE;
  2456.  
  2457.     light0pos[0]=objForce.m_xPos;
  2458.     light0pos[1]=10.0f;
  2459.     light0pos[2]=objForce.m_zPos;
  2460.     light0pos[3]=1.0f;
  2461.  
  2462.     glLightfv(GL_LIGHT0, GL_POSITION, light0pos);
  2463.  
  2464. }
  2465. void force()
  2466. {
  2467. }
  2468. void tieFighter()
  2469. {
  2470.     moveForce();
  2471.     glTranslatef(objForce.m_xPos,objForce.m_yPos,objForce.m_zPos);
  2472.     glRotatef(dRadToDeg(objForce.m_angle_radians+((float)PI/2.0f))+90, 0.0f, 1.0f, 0.0f);
  2473.  
  2474.     // Pewter
  2475.     pewterMaterial();
  2476. }
  2477. void empty()
  2478. {
  2479. }
  2480. void icosahedron()
  2481. {
  2482.     GLfloat normal[3];
  2483.     VECTOR_STRUCT_TYPE vertex[12];
  2484.     GLfloat t;
  2485.  
  2486.     setAmbientMaterialColor(0.0f,0.0f,0.5f,1.0f);
  2487.     setDiffuseMaterialColor(0.0f,0.0f,0.8f,1.0f);
  2488.  
  2489.     t=(float) sqrt((float)(5)-1)/2;
  2490.  
  2491.     /*Icoshedron*/
  2492.     vertex[0].m_x=0.0f;
  2493.     vertex[0].m_y=1.0f;
  2494.     vertex[0].m_z=t;
  2495.  
  2496.     vertex[1].m_x=0.0f;
  2497.     vertex[1].m_y=1.0f;
  2498.     vertex[1].m_z=-t;
  2499.  
  2500.     vertex[2].m_x=1.0f;
  2501.     vertex[2].m_y=t;
  2502.     vertex[2].m_z=0.0f;
  2503.  
  2504.     vertex[3].m_x=1.0f;
  2505.     vertex[3].m_y=-t;
  2506.     vertex[3].m_z=0.0f;
  2507.  
  2508.     vertex[4].m_x=0.0f;
  2509.     vertex[4].m_y=-1.0f;
  2510.     vertex[4].m_z=-t;
  2511.  
  2512.     vertex[5].m_x=0.0f;
  2513.     vertex[5].m_y=-1.0f;
  2514.     vertex[5].m_z=t;
  2515.  
  2516.     vertex[6].m_x=t;
  2517.     vertex[6].m_y=0.0f;
  2518.     vertex[6].m_z=1.0f;
  2519.  
  2520.     vertex[7].m_x=-t;
  2521.     vertex[7].m_y=0.0f;
  2522.     vertex[7].m_z=1.0f;
  2523.  
  2524.     vertex[8].m_x=t;
  2525.     vertex[8].m_y=0.0f;
  2526.     vertex[8].m_z=-1.0f;
  2527.  
  2528.     vertex[9].m_x=-t;
  2529.     vertex[9].m_y=0.0f;
  2530.     vertex[9].m_z=-1.0f;
  2531.  
  2532.     vertex[10].m_x=-1.0f;
  2533.     vertex[10].m_y=t;
  2534.     vertex[10].m_z=0.0f;
  2535.  
  2536.     vertex[11].m_x=-1.0f;
  2537.     vertex[11].m_y=-t;
  2538.     vertex[11].m_z=0.0f;
  2539.  
  2540.     /*Face 0 - 6,2,0*/
  2541.     glBegin(GL_POLYGON);
  2542.         calcNormal2(&vertex[0],&vertex[1],&vertex[2],normal);
  2543.         glNormal3f(normal[0],normal[1],normal[2]);
  2544.         glVertex3f(vertex[6].m_x,vertex[6].m_y,vertex[6].m_z);
  2545.         glVertex3f(vertex[2].m_x,vertex[2].m_y,vertex[2].m_z);
  2546.         glVertex3f(vertex[0].m_x,vertex[0].m_y,vertex[0].m_z);
  2547.     glEnd();
  2548.  
  2549.     /*Face 1 - 2,6,3*/
  2550.     glBegin(GL_POLYGON);
  2551.         calcNormal2(&vertex[0],&vertex[3],&vertex[2],normal);
  2552.         glNormal3f(normal[0],normal[1],normal[2]);
  2553.         glVertex3f(vertex[2].m_x,vertex[2].m_y,vertex[2].m_z);
  2554.         glVertex3f(vertex[6].m_x,vertex[6].m_y,vertex[6].m_z);
  2555.         glVertex3f(vertex[3].m_x,vertex[3].m_y,vertex[3].m_z);
  2556.     glEnd();
  2557.  
  2558.     /*Face 2 - 5,3,6*/
  2559.     glBegin(GL_POLYGON);
  2560.         calcNormal2(&vertex[0],&vertex[1],&vertex[3],normal);
  2561.         glNormal3f(normal[0],normal[1],normal[2]);
  2562.         glVertex3f(vertex[5].m_x,vertex[5].m_y,vertex[5].m_z);
  2563.         glVertex3f(vertex[3].m_x,vertex[3].m_y,vertex[3].m_z);
  2564.         glVertex3f(vertex[6].m_x,vertex[6].m_y,vertex[6].m_z);
  2565.     glEnd();
  2566.  
  2567.     /*Face 3 - 5,6,7*/
  2568.     glBegin(GL_POLYGON);
  2569.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2570.         glNormal3f(normal[0],normal[1],normal[2]);
  2571.         glVertex3f(vertex[5].m_x,vertex[5].m_y,vertex[5].m_z);
  2572.         glVertex3f(vertex[6].m_x,vertex[6].m_y,vertex[6].m_z);
  2573.         glVertex3f(vertex[7].m_x,vertex[7].m_y,vertex[7].m_z);
  2574.     glEnd();
  2575.  
  2576.     /*Face 4 - 0,7,6*/
  2577.     glBegin(GL_POLYGON);
  2578.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2579.         glNormal3f(normal[0],normal[1],normal[2]);
  2580.         glVertex3f(vertex[0].m_x,vertex[0].m_y,vertex[0].m_z);
  2581.         glVertex3f(vertex[7].m_x,vertex[7].m_y,vertex[7].m_z);
  2582.         glVertex3f(vertex[6].m_x,vertex[6].m_y,vertex[6].m_z);
  2583.     glEnd();
  2584.  
  2585.  
  2586.     /*Face 5 - 3,8,2*/
  2587.     glBegin(GL_POLYGON);
  2588.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2589.         glNormal3f(normal[0],normal[1],normal[2]);
  2590.         glVertex3f(vertex[3].m_x,vertex[3].m_y,vertex[3].m_z);
  2591.         glVertex3f(vertex[8].m_x,vertex[8].m_y,vertex[8].m_z);
  2592.         glVertex3f(vertex[2].m_x,vertex[2].m_y,vertex[2].m_z);
  2593.     glEnd();
  2594.  
  2595.     /*Face 6 - 2,8,1*/
  2596.     glBegin(GL_POLYGON);
  2597.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2598.         glNormal3f(normal[0],normal[1],normal[2]);
  2599.         glVertex3f(vertex[2].m_x,vertex[2].m_y,vertex[2].m_z);
  2600.         glVertex3f(vertex[8].m_x,vertex[8].m_y,vertex[8].m_z);
  2601.         glVertex3f(vertex[1].m_x,vertex[1].m_y,vertex[1].m_z);
  2602.     glEnd();
  2603.  
  2604.  
  2605.     /*Face 7 - 1,0,2*/
  2606.     glBegin(GL_POLYGON);
  2607.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2608.         glNormal3f(normal[0],normal[1],normal[2]);
  2609.         glVertex3f(vertex[1].m_x,vertex[1].m_y,vertex[1].m_z);
  2610.         glVertex3f(vertex[0].m_x,vertex[0].m_y,vertex[0].m_z);
  2611.         glVertex3f(vertex[2].m_x,vertex[2].m_y,vertex[2].m_z);
  2612.     glEnd();
  2613.  
  2614.     /*Face 8 - 0,1,10*/
  2615.     glBegin(GL_POLYGON);
  2616.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2617.         glNormal3f(normal[0],normal[1],normal[2]);
  2618.         glVertex3f(vertex[0].m_x,vertex[0].m_y,vertex[0].m_z);
  2619.         glVertex3f(vertex[1].m_x,vertex[1].m_y,vertex[1].m_z);
  2620.         glVertex3f(vertex[10].m_x,vertex[10].m_y,vertex[10].m_z);
  2621.     glEnd();
  2622.  
  2623.         /*Face 9 - 9,10,1*/
  2624.     glBegin(GL_POLYGON);
  2625.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2626.         glNormal3f(normal[0],normal[1],normal[2]);
  2627.         glVertex3f(vertex[9].m_x,vertex[9].m_y,vertex[9].m_z);
  2628.         glVertex3f(vertex[10].m_x,vertex[10].m_y,vertex[10].m_z);
  2629.         glVertex3f(vertex[1].m_x,vertex[1].m_y,vertex[1].m_z);
  2630.     glEnd();
  2631.  
  2632.         /*Face 10 - 9,1,8*/
  2633.     glBegin(GL_POLYGON);
  2634.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2635.         glNormal3f(normal[0],normal[1],normal[2]);
  2636.         glVertex3f(vertex[9].m_x,vertex[9].m_y,vertex[9].m_z);
  2637.         glVertex3f(vertex[1].m_x,vertex[1].m_y,vertex[1].m_z);
  2638.         glVertex3f(vertex[8].m_x,vertex[8].m_y,vertex[8].m_z);
  2639.     glEnd();
  2640.  
  2641.         /*Face 11 - 8,3,4*/
  2642.     glBegin(GL_POLYGON);
  2643.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2644.         glNormal3f(normal[0],normal[1],normal[2]);
  2645.         glVertex3f(vertex[8].m_x,vertex[8].m_y,vertex[8].m_z);
  2646.         glVertex3f(vertex[3].m_x,vertex[3].m_y,vertex[3].m_z);
  2647.         glVertex3f(vertex[4].m_x,vertex[4].m_y,vertex[4].m_z);
  2648.     glEnd();
  2649.  
  2650.         /*Face 12 - 3,5,4*/
  2651.     glBegin(GL_POLYGON);
  2652.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2653.         glNormal3f(normal[0],normal[1],normal[2]);
  2654.         glVertex3f(vertex[3].m_x,vertex[3].m_y,vertex[3].m_z);
  2655.         glVertex3f(vertex[5].m_x,vertex[5].m_y,vertex[5].m_z);
  2656.         glVertex3f(vertex[4].m_x,vertex[4].m_y,vertex[4].m_z);
  2657.     glEnd();
  2658.  
  2659.             /*Face 13 - 4,5,11*/
  2660.     glBegin(GL_POLYGON);
  2661.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2662.         glNormal3f(normal[0],normal[1],normal[2]);
  2663.         glVertex3f(vertex[4].m_x,vertex[4].m_y,vertex[4].m_z);
  2664.         glVertex3f(vertex[5].m_x,vertex[5].m_y,vertex[5].m_z);
  2665.         glVertex3f(vertex[11].m_x,vertex[11].m_y,vertex[11].m_z);
  2666.     glEnd();
  2667.  
  2668.             /*Face 14 - 7,10,11*/
  2669.     glBegin(GL_POLYGON);
  2670.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2671.         glNormal3f(normal[0],normal[1],normal[2]);
  2672.         glVertex3f(vertex[7].m_x,vertex[7].m_y,vertex[7].m_z);
  2673.         glVertex3f(vertex[10].m_x,vertex[10].m_y,vertex[10].m_z);
  2674.         glVertex3f(vertex[11].m_x,vertex[11].m_y,vertex[11].m_z);
  2675.     glEnd();
  2676.  
  2677.     /*Face 15 - 10,7,0*/
  2678.     glBegin(GL_POLYGON);
  2679.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2680.         glNormal3f(normal[0],normal[1],normal[2]);
  2681.         glVertex3f(vertex[10].m_x,vertex[10].m_y,vertex[10].m_z);
  2682.         glVertex3f(vertex[7].m_x,vertex[7].m_y,vertex[7].m_z);
  2683.         glVertex3f(vertex[0].m_x,vertex[0].m_y,vertex[0].m_z);
  2684.     glEnd();
  2685.  
  2686.     /*Face 16 - 11,9,4*/
  2687.     glBegin(GL_POLYGON);
  2688.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2689.         glNormal3f(normal[0],normal[1],normal[2]);
  2690.         glVertex3f(vertex[11].m_x,vertex[11].m_y,vertex[11].m_z);
  2691.         glVertex3f(vertex[9].m_x,vertex[9].m_y,vertex[9].m_z);
  2692.         glVertex3f(vertex[4].m_x,vertex[4].m_y,vertex[4].m_z);
  2693.     glEnd();
  2694.  
  2695.     /*Face 17 - 8,4,9*/
  2696.     glBegin(GL_POLYGON);
  2697.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2698.         glNormal3f(normal[0],normal[1],normal[2]);
  2699.         glVertex3f(vertex[8].m_x,vertex[8].m_y,vertex[8].m_z);
  2700.         glVertex3f(vertex[4].m_x,vertex[4].m_y,vertex[4].m_z);
  2701.         glVertex3f(vertex[9].m_x,vertex[9].m_y,vertex[9].m_z);
  2702.     glEnd();
  2703.  
  2704.     /*Face 18 - 7,11,5*/
  2705.     glBegin(GL_POLYGON);
  2706.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2707.         glNormal3f(normal[0],normal[1],normal[2]);
  2708.         glVertex3f(vertex[7].m_x,vertex[7].m_y,vertex[7].m_z);
  2709.         glVertex3f(vertex[11].m_x,vertex[11].m_y,vertex[11].m_z);
  2710.         glVertex3f(vertex[5].m_x,vertex[5].m_y,vertex[5].m_z);
  2711.     glEnd();
  2712.     
  2713.     /*Face 19 - 10,9,11*/
  2714.     glBegin(GL_POLYGON);
  2715.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2716.         glNormal3f(normal[0],normal[1],normal[2]);
  2717.         glVertex3f(vertex[10].m_x,vertex[10].m_y,vertex[10].m_z);
  2718.         glVertex3f(vertex[9].m_x,vertex[9].m_y,vertex[9].m_z);
  2719.         glVertex3f(vertex[11].m_x,vertex[11].m_y,vertex[11].m_z);
  2720.     glEnd();
  2721.  
  2722. }
  2723. void tetrahedron()
  2724. {
  2725.     GLfloat normal[3];
  2726.     VECTOR_STRUCT_TYPE vertex[12];
  2727.  
  2728.     /*Tetrahedron*/
  2729.     vertex[0].m_x=1.0f;
  2730.     vertex[0].m_y=1.0f;
  2731.     vertex[0].m_z=1.0f;
  2732.  
  2733.     vertex[1].m_x=1.0f;
  2734.     vertex[1].m_y=-1.0f;
  2735.     vertex[1].m_z=-1.0f;
  2736.  
  2737.     vertex[2].m_x=-1.0f;
  2738.     vertex[2].m_y=-1.0f;
  2739.     vertex[2].m_z=1.0f;
  2740.  
  2741.     vertex[3].m_x=-1.0f;
  2742.     vertex[3].m_y=1.0f;
  2743.     vertex[3].m_z=-1.0f;
  2744.  
  2745.     /*Face 0 - 1,2,3*/
  2746.     glBegin(GL_POLYGON);
  2747.         calcNormal2(&vertex[1],&vertex[2],&vertex[3],normal);
  2748.         glNormal3f(normal[0],normal[1],normal[2]);
  2749.         glVertex3f(vertex[1].m_x,vertex[1].m_y,vertex[1].m_z);
  2750.         glVertex3f(vertex[2].m_x,vertex[2].m_y,vertex[2].m_z);
  2751.         glVertex3f(vertex[3].m_x,vertex[3].m_y,vertex[3].m_z);
  2752.     glEnd();
  2753.  
  2754.     /*Face 1 - 0,3,2*/
  2755.     glBegin(GL_POLYGON);
  2756.         calcNormal2(&vertex[0],&vertex[3],&vertex[2],normal);
  2757.         glNormal3f(normal[0],normal[1],normal[2]);
  2758.         glVertex3f(vertex[0].m_x,vertex[0].m_y,vertex[0].m_z);
  2759.         glVertex3f(vertex[3].m_x,vertex[3].m_y,vertex[3].m_z);
  2760.         glVertex3f(vertex[2].m_x,vertex[2].m_y,vertex[2].m_z);
  2761.     glEnd();
  2762.  
  2763.     /*Face 2 - 0,1,3*/
  2764.     glBegin(GL_POLYGON);
  2765.         calcNormal2(&vertex[0],&vertex[1],&vertex[3],normal);
  2766.         glNormal3f(normal[0],normal[1],normal[2]);
  2767.         glVertex3f(vertex[0].m_x,vertex[0].m_y,vertex[0].m_z);
  2768.         glVertex3f(vertex[1].m_x,vertex[1].m_y,vertex[1].m_z);
  2769.         glVertex3f(vertex[3].m_x,vertex[3].m_y,vertex[3].m_z);
  2770.     glEnd();
  2771.  
  2772.     /*Face 3 - 0,2,1*/
  2773.     glBegin(GL_POLYGON);
  2774.         calcNormal2(&vertex[0],&vertex[2],&vertex[1],normal);
  2775.         glNormal3f(normal[0],normal[1],normal[2]);
  2776.         glVertex3f(vertex[0].m_x,vertex[0].m_y,vertex[0].m_z);
  2777.         glVertex3f(vertex[2].m_x,vertex[2].m_y,vertex[2].m_z);
  2778.         glVertex3f(vertex[1].m_x,vertex[1].m_y,vertex[1].m_z);
  2779.     glEnd();
  2780. }
  2781. int getAvailableMissile()
  2782. {
  2783.     int i;
  2784.     for(i=0; i<NUMBER_OF_MISSILES; i++)
  2785.     {
  2786.         if (shipMissile[i].m_available_flag==TRUE)
  2787.         {
  2788.             return(i);
  2789.         }
  2790.     }
  2791.     return(-1);
  2792. }
  2793.  
  2794. void collision(int index1, int index2)
  2795. {
  2796. GLfloat angle, velocity;
  2797. //1/2 m1*pow(v1,2)=1/2*m1*pow(v1prim,2)+1/2*m2*pow(v2prim,2)
  2798.  
  2799.     /*The momentum type is oblique collision.  However, I use a headon elastic equation.*/
  2800.     objAsteroid[index1].m_angle_radians+=3.142f;
  2801.     objAsteroid[index2].m_angle_radians+=3.142f;
  2802.  
  2803.     //Asteroid 1
  2804.     angle=objAsteroid[index1].m_angle_radians;
  2805.     velocity=objAsteroid[index1].m_velocity;
  2806.  
  2807.     objAsteroid[index1].dir_x= (GLfloat) (velocity*cos(angle));
  2808.     objAsteroid[index1].dir_z= (GLfloat) (-velocity*sin(angle));
  2809.  
  2810.     //Asteroid 2
  2811.     angle=objAsteroid[index2].m_angle_radians;
  2812.     velocity=objAsteroid[index2].m_velocity;
  2813.  
  2814.     objAsteroid[index2].dir_x= (GLfloat) (velocity*cos(angle));
  2815.     objAsteroid[index2].dir_z= (GLfloat) (-velocity*sin(angle));
  2816. }
  2817. void hyperboloid()
  2818. {
  2819.     GLfloat vertexes[4][3];
  2820.     GLfloat normal[3];
  2821.     GLfloat x;
  2822.     GLfloat y;
  2823.     GLfloat z;
  2824.     GLfloat phi;
  2825.     GLfloat theta;
  2826.     GLfloat v,u;
  2827.     GLfloat r;
  2828.     GLfloat h;
  2829.  
  2830.     r=1.0f;
  2831.     h=2.0f;
  2832.  
  2833.     for(phi=-180.0f; phi <= 180.0f; phi+=40.0f)
  2834.     {
  2835.         for(theta=-270.0f; theta<=90.0f; theta+=20.0f)
  2836.         {
  2837.         v=(phi/180.0f*3.142f);
  2838.         u=(theta/180.0f*3.142f);
  2839.         /*Vertex 1*/
  2840.         x= (GLfloat) (r*(1/cos(v))*cos(u));
  2841.         y= (GLfloat) (r*(1/cos(v))*sin(u));
  2842.         z= (GLfloat) (h*tan(v));
  2843.         vertexes[0][0]=x;
  2844.         vertexes[0][1]=y;
  2845.         vertexes[0][2]=z;
  2846.         /*Vertex 2*/
  2847.         v=(phi/180.0f*3.142f);
  2848.         u=((theta+20.0f)/180.0f*3.142f);
  2849.  
  2850.         x= (GLfloat) (r*(1/cos(v))*cos(u));
  2851.         y= (GLfloat) (r*(1/cos(v))*sin(u));
  2852.         z= (GLfloat) (h*tan(v));
  2853.  
  2854.         vertexes[1][0]=x;
  2855.         vertexes[1][1]=y;
  2856.         vertexes[1][2]=z;
  2857.         /*Vertex 3*/
  2858.         v=((phi+20.0f)/180.0f*3.142f);
  2859.         u=((theta+20.0f)/180.0f*3.142f);
  2860.  
  2861.         x= (GLfloat) (r*(1/cos(v))*cos(u));
  2862.         y= (GLfloat) (r*(1/cos(v))*sin(u));
  2863.         z= (GLfloat) (h*tan(v));
  2864.  
  2865.         vertexes[2][0]=x;
  2866.         vertexes[2][1]=y;
  2867.         vertexes[2][2]=z;
  2868.         /*Vertex 4*/
  2869.         v=((phi+20.0f)/180.0f*3.142f);
  2870.         u=((theta)/180.0f*3.142f);
  2871.  
  2872.         x= (GLfloat) (r*(1/cos(v))*cos(u));
  2873.         y= (GLfloat) (r*(1/cos(v))*sin(u));
  2874.         z= (GLfloat) (h*tan(v));
  2875.  
  2876.         vertexes[3][0]=x;
  2877.         vertexes[3][1]=y;
  2878.         vertexes[3][2]=z;
  2879.         calcNormal(vertexes,normal);
  2880.  
  2881.         glBegin(GL_POLYGON);
  2882.             glNormal3f(normal[0],normal[1],normal[2]);
  2883.             glVertex3f(vertexes[0][0],vertexes[0][1],vertexes[0][2]);
  2884.             glVertex3f(vertexes[1][0],vertexes[1][1],vertexes[1][2]);
  2885.             glVertex3f(vertexes[2][0],vertexes[2][1],vertexes[2][2]);
  2886.             glVertex3f(vertexes[3][0],vertexes[3][1],vertexes[3][2]);
  2887.         glEnd();
  2888.         }
  2889.     }
  2890. }
  2891. void CMy3DFontView::buildBonusObject()
  2892. {
  2893.  int i;
  2894.  int j;
  2895.  int index;
  2896.  
  2897.  GLfloat x;
  2898.  GLfloat z;
  2899.  
  2900.     z = -45.0f;
  2901.     for(i=0; i<=9; i++)
  2902.     {
  2903.         x = -45.0f;
  2904.  
  2905.         for(j=0; j<=9; j++)
  2906.         {
  2907.             if(vMap[i][j] == BONUS_TYPE)
  2908.             {
  2909.                 index=getBonusObject();
  2910.                 objBonusList[index].m_available_flag=FALSE;
  2911.                 objBonusList[index].m_active_flag=TRUE;
  2912.                 objBonusList[index].m_x=x;
  2913.                 objBonusList[index].m_y=1.5f;
  2914.                 objBonusList[index].m_z=z;
  2915.             }
  2916.             x = x + (GRID_SIZE/10);
  2917.         }
  2918.         z = z + (GRID_SIZE/10);
  2919.     }    
  2920.  
  2921. }
  2922. void CMy3DFontView::bonus_configuration()
  2923. {
  2924.     //Row 1
  2925.     vMap[0][0] = BONUS_TYPE;
  2926.     vMap[0][1] = 0;
  2927.     vMap[0][2] = 0;
  2928.     vMap[0][3] = 0;
  2929.     vMap[0][4] = 0;
  2930.     vMap[0][5] = 0;
  2931.     vMap[0][6] = 0;
  2932.     vMap[0][7] = 0;
  2933.     vMap[0][8] = 0;
  2934.     vMap[0][9] = 0;
  2935.     //Row 2
  2936.     vMap[1][0] = 0;
  2937.     vMap[1][1] = 0;
  2938.     vMap[1][2] = 0;
  2939.     vMap[1][3] = 0;
  2940.     vMap[1][4] = 0;
  2941.     vMap[1][5] = 0;
  2942.     vMap[1][6] = 0;
  2943.     vMap[1][7] = 0;
  2944.     vMap[1][8] = 0;
  2945.     vMap[1][9] = 0;
  2946.     //Row 3
  2947.     vMap[2][0] = 0;
  2948.     vMap[2][1] = 0;
  2949.     vMap[2][2] = 0;
  2950.     vMap[2][3] = 0;
  2951.     vMap[2][4] = BONUS_TYPE;
  2952.     vMap[2][5] = 0;
  2953.     vMap[2][6] = 0;
  2954.     vMap[2][7] = 0;
  2955.     vMap[2][8] = 0;
  2956.     vMap[2][9] = 0;
  2957.     //Row 4
  2958.     vMap[3][0] = 0;
  2959.     vMap[3][1] = 0;
  2960.     vMap[3][2] = 0;
  2961.     vMap[3][3] = 0;
  2962.     vMap[3][4] = 0;
  2963.     vMap[3][5] = BONUS_TYPE;
  2964.     vMap[3][6] = 0;
  2965.     vMap[3][7] = 0;
  2966.     vMap[3][8] = 0;
  2967.     vMap[3][9] = 0;
  2968.     //Row 5
  2969.     vMap[4][0] = 0;
  2970.     vMap[4][1] = 0;
  2971.     vMap[4][2] = 0;
  2972.     vMap[4][3] = 0;
  2973.     vMap[4][4] = 0;
  2974.     vMap[4][5] = 0;
  2975.     vMap[4][6] = 0;
  2976.     vMap[4][7] = 0;
  2977.     vMap[4][8] = 0;
  2978.     vMap[4][9] = 0;
  2979.     //Row 6
  2980.     vMap[5][0] = 0;
  2981.     vMap[5][1] = 0;
  2982.     vMap[5][2] = 0;
  2983.     vMap[5][3] = 0;
  2984.     vMap[5][4] = 0;
  2985.     vMap[5][5] = 0;
  2986.     vMap[5][6] = 0;
  2987.     vMap[5][7] = 0;
  2988.     vMap[5][8] = 0;
  2989.     vMap[5][9] = BONUS_TYPE;
  2990.     //Row 7
  2991.     vMap[6][0] = 0;
  2992.     vMap[6][1] = 0;
  2993.     vMap[6][2] = 0;
  2994.     vMap[6][3] = 0;
  2995.     vMap[6][4] = 0;
  2996.     vMap[6][5] = 0;
  2997.     vMap[6][6] = 0;
  2998.     vMap[6][7] = 0;
  2999.     vMap[6][8] = 0;
  3000.     vMap[6][9] = 0;
  3001.     //Row 8
  3002.     vMap[7][0] = BONUS_TYPE;
  3003.     vMap[7][1] = 0;
  3004.     vMap[7][2] = 0;
  3005.     vMap[7][3] = 0;
  3006.     vMap[7][4] = 0;
  3007.     vMap[7][5] = 0;
  3008.     vMap[7][6] = 0;
  3009.     vMap[7][7] = 0;
  3010.     vMap[7][8] = 0;
  3011.     vMap[7][9] = 0;
  3012.     //Row 9
  3013.     vMap[8][0] = 0;
  3014.     vMap[8][1] = 0;
  3015.     vMap[8][2] = 0;
  3016.     vMap[8][3] = 0;
  3017.     vMap[8][4] = 0;
  3018.     vMap[8][5] = 0;
  3019.     vMap[8][6] = 0;
  3020.     vMap[8][7] = 0;
  3021.     vMap[8][8] = 0;
  3022.     vMap[8][9] = 0;
  3023.     //Row 10
  3024.     vMap[9][0] = 0;
  3025.     vMap[9][1] = 0;
  3026.     vMap[9][2] = 0;
  3027.     vMap[9][3] = 0;
  3028.     vMap[9][4] = 0;
  3029.     vMap[9][5] = BONUS_TYPE;
  3030.     vMap[9][6] = 0;
  3031.     vMap[9][7] = 0;
  3032.     vMap[9][8] = 0;
  3033.     vMap[9][9] = 0;
  3034.  
  3035. }
  3036. int CMy3DFontView::getObjectCount(int type)
  3037. {
  3038.     int i;
  3039.     int retval=0;
  3040.  
  3041.     if(type==BONUS_TYPE)
  3042.     {
  3043.         for (i=0; i<OBJECT_LIST_SIZE; i++)
  3044.         {
  3045.             if(objBonusList[i].m_active_flag==TRUE)
  3046.             {
  3047.                 retval++;
  3048.             }
  3049.         }
  3050.     }
  3051.     return(retval);
  3052. }
  3053.  
  3054. void CMy3DFontView::drawBonusObjectList()
  3055. {
  3056.     int i;
  3057.     int color;
  3058.  
  3059.         setSpecularMaterialColor(1.0f,1.0f,1.0f,1.0f);
  3060.         setMaterialShininess(128.0f);
  3061.  
  3062.         setAmbientMaterialColor(0.3f,0.3f,0.3f,1.0f);
  3063.  
  3064.         for(i=0; i<OBJECT_LIST_SIZE; i++)
  3065.         {
  3066.             if(objBonusList[i].m_available_flag==FALSE)
  3067.             {
  3068.                 color=rand()%3;
  3069.                 switch(color)
  3070.                 {
  3071.                 case 0:
  3072.                     setDiffuseMaterialColor(0.8f,0.0f,0.0f,1.0f);
  3073.                     break;
  3074.                 case 1:
  3075.                     setDiffuseMaterialColor(0.0f,0.8f,0.0f,1.0f);
  3076.                     break;
  3077.                 case 2:
  3078.                     setDiffuseMaterialColor(0.0f,0.0f,0.8f,1.0f);
  3079.                     break;
  3080.                 case 3:
  3081.                     setDiffuseMaterialColor(0.8f,0.8f,0.0f,1.0f);
  3082.                     break;
  3083.                 }
  3084.  
  3085.                 glPushMatrix();
  3086.                     glTranslatef(objBonusList[i].m_x,objBonusList[i].m_y,objBonusList[i].m_z);
  3087.                     glRotatef(90.0f,1.0f,0.0f,0.0f);
  3088.                      hyperboloid();
  3089.                 glPopMatrix();
  3090.             }
  3091.         }
  3092.  
  3093. }
  3094. void CMy3DFontView::drawMineObjectList()
  3095. {
  3096.     int i;
  3097.     GLfloat x,y,z;
  3098.     int retval;
  3099.  
  3100.         for(i=0; i<MINE_LIST_SIZE; i++)
  3101.         {
  3102.             if(objMineList[i].m_available_flag==FALSE)
  3103.             {
  3104.                 
  3105.                 x=objMineList[i].m_x;
  3106.                 y=objMineList[i].m_y;
  3107.                 z=objMineList[i].m_z;
  3108.  
  3109.                 retval=checkShipHit(x,y,z);
  3110.                 if(retval==1)
  3111.                 {
  3112.                     objMineList[i].m_available_flag=TRUE;
  3113.                     objMineList[i].m_active_flag=FALSE;
  3114.                     continue;
  3115.                 }
  3116.  
  3117.                 retval=checkAsteroidHit(x,y,z);
  3118.  
  3119.                 if(objMineList[i].m_direction==RIGHT_DIRECTION)
  3120.                 {
  3121.                     if ( ((x+5.0f)>GRID_SIZE) || (retval==1))
  3122.                     {
  3123.                         objMineList[i].m_direction=LEFT_DIRECTION;
  3124.                         z+=5.0f;
  3125.                     }
  3126.                     else
  3127.                     {
  3128.                         x+=5.0f;
  3129.                     }
  3130.                 }
  3131.                 else
  3132.                 {
  3133.                     if ( ((x-5.0f)<-GRID_SIZE) || (retval==1))
  3134.                     {
  3135.                         objMineList[i].m_direction=RIGHT_DIRECTION;
  3136.                         z+=5.0f;
  3137.                     }
  3138.                     else
  3139.                     {
  3140.                         x-=5.0f;
  3141.                     }
  3142.                 }
  3143.  
  3144.                 if (z>GRID_SIZE)
  3145.                 {
  3146.                     objMineList[i].m_available_flag=TRUE;
  3147.                     objMineList[i].m_active_flag=FALSE;
  3148.                 }
  3149.  
  3150.                 objMineList[i].m_x=x;
  3151.                 objMineList[i].m_y=y;
  3152.                 objMineList[i].m_z=z;
  3153.  
  3154.                 glPushMatrix();
  3155.                     glTranslatef(objMineList[i].m_x,objMineList[i].m_y,objMineList[i].m_z);
  3156.                     drawMine();
  3157.                 glPopMatrix();
  3158.             }
  3159.         }
  3160.  
  3161. }
  3162.  
  3163. int CMy3DFontView::getBonusObject()
  3164. {
  3165.     int i;
  3166.     for (i=0; i<OBJECT_LIST_SIZE; i++)
  3167.     {
  3168.         if (objBonusList[i].m_available_flag==TRUE)
  3169.         {
  3170.             return(i);
  3171.         }
  3172.     }
  3173.     return(-1);
  3174. }
  3175. int getMineObject()
  3176. {
  3177.     int i;
  3178.     for (i=0; i<MINE_LIST_SIZE; i++)
  3179.     {
  3180.         if (objMineList[i].m_available_flag==TRUE)
  3181.         {
  3182.             return(i);
  3183.         }
  3184.     }
  3185.     return(-1);
  3186. }
  3187. void checkBonusCollision()
  3188. {
  3189.     GLfloat distance;
  3190.     GLfloat x,y,z;
  3191.     int i;
  3192.  
  3193.         for(i=0; i<OBJECT_LIST_SIZE; i++)
  3194.         {
  3195.             if(objBonusList[i].m_active_flag==TRUE)
  3196.             {
  3197.  
  3198.                 x=objForce.m_xPos-objBonusList[i].m_x;
  3199.                 y=objForce.m_yPos-objBonusList[i].m_y;
  3200.                 z=objForce.m_zPos-objBonusList[i].m_z;
  3201.  
  3202.                 distance=(GLfloat)sqrt(x*x+y*y+z*z);
  3203.  
  3204.                 if (distance<20)
  3205.                 {
  3206.                     objBonusList[i].m_available_flag=TRUE;
  3207.                     objBonusList[i].m_active_flag=FALSE;
  3208.                     objForce.m_shield+=10;
  3209.                     break;
  3210.                 }
  3211.  
  3212.             }
  3213.         }
  3214.  
  3215. }
  3216. void Enemy()
  3217. {
  3218.     drawEnemyMissiles();
  3219. }
  3220. void drawEnemyBody()
  3221. {
  3222.     glPushMatrix();
  3223.  
  3224.         glTranslatef(50.0f,48.0f,0.0f);
  3225.         
  3226.         setAmbientMaterialColor(0.5f,0.5f,0.5f,1.0f);
  3227.         setDiffuseMaterialColor(1.0f,1.0f,1.0f,1.0f);
  3228.         setSpecularMaterialColor(1.0f,1.0f,1.0f,1.0f);
  3229.         setMaterialShininess(100.0f);
  3230.  
  3231.         glNormal3f(0.0f,0.0f,1.0f);
  3232.  
  3233.         glRotatef(90.0f,0.0f,0.0f,1.0f);
  3234.  
  3235.         cylinder(10.0f,150.0f);
  3236.  
  3237.  
  3238.     glPopMatrix();
  3239.  
  3240.     // Left Cyl
  3241.     glPushMatrix();
  3242.         
  3243.         glTranslatef(140.0f,48.0f,-10.0f);
  3244.         glNormal3f(0.0f,0.0f,1.0f);
  3245.         glRotatef(90.0f,0.0f,0.0f,1.0f);
  3246.         
  3247.         cylinder(11.0f,60.0f);
  3248.  
  3249.     glPopMatrix();
  3250.  
  3251.     // Right Cyl
  3252.     glPushMatrix();
  3253.         
  3254.         glTranslatef(140.0f,48.0f,10.0f);
  3255.         glNormal3f(0.0f,0.0f,1.0f);
  3256.         glRotatef(90.0f,0.0f,0.0f,1.0f);
  3257.         
  3258.         cylinder(11.0f,60.0f);
  3259.         glTranslatef(-140.0f,-48.0f,-10.0f);
  3260.  
  3261.     glPopMatrix();
  3262.  
  3263.     // Top Cyl
  3264.     glPushMatrix();
  3265.         
  3266.         glTranslatef(140.0f,58.0f,0.0f);
  3267.         glNormal3f(0.0f,0.0f,1.0f);
  3268.         glRotatef(90.0f,0.0f,0.0f,1.0f);
  3269.         cylinder(11.0f,60.0f);
  3270.     glPopMatrix();
  3271.  
  3272.     // Bottom Cyl
  3273.     glPushMatrix();
  3274.         
  3275.         glTranslatef(140.0f,38.0f,0.0f);
  3276.         glNormal3f(0.0f,0.0f,1.0f);
  3277.         glRotatef(90.0f,0.0f,0.0f,1.0f);
  3278.         cylinder(11.0f,60.0f);
  3279.  
  3280.     glPopMatrix();
  3281.  
  3282.     // Sphere
  3283.     glPushMatrix();
  3284.         
  3285.         glTranslatef(200.0f,48.0f,0.0f);
  3286.         glNormal3f(0.0f,0.0f,1.0f);
  3287.         glRotatef(90.0f,0.0f,0.0f,1.0f);
  3288.         
  3289.         sphere(20.0f);
  3290.  
  3291.     glPopMatrix();
  3292.  
  3293.     glPushMatrix();
  3294.         glTranslatef(200.0f,48.0f,0.0f);
  3295.         
  3296.         // Bottom
  3297.         glPushMatrix();
  3298.         
  3299.             //glRotatef(engRot,0.0,0.0,1.0);
  3300.             cylinder(8.0f,70.0f);
  3301.             glTranslatef(0.0f,-75.0f,0.0f);
  3302.             sphere(10.0f);
  3303.             glRotatef(60.0f,0.0f,0.0f,1.0f);
  3304.             cylinder(8.0f,50.0f);
  3305.         
  3306.         glPopMatrix();            
  3307.  
  3308.         glRotatef(90.0f,1.0f,0.0f,0.0f);
  3309.  
  3310.         // Right
  3311.         glPushMatrix();
  3312.         
  3313.             //glRotatef(engRot,0.0,0.0,1.0);
  3314.             cylinder(8.0f,70.0f);
  3315.             glTranslatef(0.0f,-75.0f,0.0f);
  3316.             sphere(10.0f);
  3317.             glRotatef(60.0f,0.0f,0.0f,1.0f);
  3318.             cylinder(8.0f,50.0f);
  3319.         
  3320.         glPopMatrix();
  3321.  
  3322.         glRotatef(90.0f,1.0f,0.0f,0.0f);
  3323.  
  3324.         // Top
  3325.         glPushMatrix();
  3326.         
  3327.             //glRotatef(engRot,0.0,0.0,1.0);
  3328.             cylinder(8.0f,70.0f);
  3329.             glTranslatef(0.0f,-75.0f,0.0f);
  3330.             sphere(10.0f);
  3331.             glRotatef(60.0f,0.0f,0.0f,1.0f);
  3332.             cylinder(8.0f,50.0f);
  3333.         
  3334.         glPopMatrix();
  3335.         
  3336.                     
  3337.         glRotatef(90.0f,1.0f,0.0f,0.0f);
  3338.  
  3339.         // Left
  3340.         glPushMatrix();
  3341.         
  3342.             //glRotatef(engRot,0.0,0.0,1.0);
  3343.             cylinder(8.0f,70.0f);
  3344.             glTranslatef(0.0f,-75.0f,0.0f);
  3345.             sphere(10.0f);
  3346.             glRotatef(60.0f,0.0f,0.0f,1.0f);
  3347.             cylinder(8.0f,50.0f);
  3348.         
  3349.         glPopMatrix();
  3350.  
  3351.     glPopMatrix();
  3352.  
  3353.     glTranslatef(-80.0f,-50.0f,0.0f);
  3354.  
  3355.     // Back - Connect
  3356.     
  3357.     setAmbientMaterialColor(0.5f,0.5f,0.5f,1.0f);
  3358.     setDiffuseMaterialColor(1.0f,1.0f,1.0f,1.0f);
  3359.     setSpecularMaterialColor(1.0f,1.0f,1.0f,1.0f);
  3360.     setMaterialShininess(100.0f);
  3361.     
  3362.     glBegin(GL_POLYGON);
  3363.         //glNormal3f(0.0f,0.0f,1.0f);
  3364.         glNormal3f(1.0f,0.0f,0.0f);
  3365.         glVertex3f(200.0f,112.0f,20.0f);
  3366.         glVertex3f(200.0f,80.0f,20.0f);
  3367.         glVertex3f(200.0f,80.0f,-20.0f);
  3368.         glVertex3f(200.0f,112.0f,-20.0f);
  3369.         glVertex3f(200.0f,112.0f,20.0f);
  3370.     glEnd();
  3371.  
  3372.     // Top
  3373.     
  3374.     glBegin(GL_POLYGON);
  3375.         //glNormal3f(0.0f,0.0f,1.0f);
  3376.         glNormal3f(-0.06651901052377393f,-0.997785157856609f,0.0f);
  3377.  
  3378.         glVertex3f(200.0f,112.0f,20.0f);
  3379.         glVertex3f(80.0f,120.0f,20.0f);
  3380.         glVertex3f(80.0f,120.0f,-20.0f);
  3381.         glVertex3f(200.0f,112.0f,-20.0f);
  3382.         glVertex3f(200.0f,112.0f,20.0f);
  3383.     glEnd();
  3384.  
  3385.  
  3386.     // Front
  3387.     
  3388.     glBegin(GL_POLYGON);
  3389.         //glNormal3f(0.0f,0.0f,1.0f);
  3390.         glNormal3f(0.7071067811865475f,-0.7071067811865475f,0.0f);
  3391.         glVertex3f(80.0f,120.0f,20.0f);
  3392.         glVertex3f(0.0f,40.0f,60.0f);
  3393.         glVertex3f(0.0f,40.0f,-60.0f);
  3394.         glVertex3f(80.0f,120.0f,-20.0f);
  3395.         glVertex3f(80.0f,120.0f,20.0f);
  3396.     glEnd();
  3397.     
  3398.     // Bottom Front
  3399.     
  3400.     glBegin(GL_POLYGON);
  3401.         //glNormal3f(0.0f,0.0f,1.0f);
  3402.         glNormal3f(0.3713906763541037f,0.9284766908852593f,0.0f);
  3403.  
  3404.         glVertex3f(0.0f,40.0f,60.0f);
  3405.         glVertex3f(100.0f,0.0f,0.0f);
  3406.         glVertex3f(0.0f,40.0f,-60.0f);
  3407.         glVertex3f(0.0f,40.0f,60.0f);
  3408.     glEnd();
  3409.  
  3410.  
  3411.     // Bottom Back
  3412.     
  3413.     glBegin(GL_POLYGON);
  3414.         //glNormal3f(0.0f,0.0f,1.0f);
  3415.         glNormal3f(0.6246950475544243f,-0.7808688094430304f,0.0f);
  3416.         glVertex3f(200.0f,80.0f,-20.0f);
  3417.         glVertex3f(200.0f,80.0f,20.0f);
  3418.         glVertex3f(100.0f,0.0f,0.0f);
  3419.         glVertex3f(200.0f,80.0f,-20.0f);
  3420.     glEnd();
  3421.  
  3422.     // Left Side Bottom
  3423.     
  3424.     glBegin(GL_POLYGON);
  3425.         //glNormal3f(0.0f,0.0f,1.0f);
  3426.         //glNormal3f(0.48507125007266594f,-0.7276068751089989f,0.48507125007266594f);
  3427.         glNormal3f(-0.48507125007266594f,0.7276068751089989f,-0.48507125007266594f);
  3428.  
  3429.         glVertex3f(100.0f,0.0f,0.0f);
  3430.         glVertex3f(200.0f,80.0f,20.0f);
  3431.         glVertex3f(100.0f,40.0f,60.0f);
  3432.         glVertex3f(0.0f,40.0f,60.0f);
  3433.         glVertex3f(100.0f,0.0f,0.0f);
  3434.     glEnd();
  3435.  
  3436.     
  3437.     // Left Side Top
  3438.  
  3439.     glBegin(GL_POLYGON);
  3440.         //glNormal3f(0.0f,0.0f,1.0f);
  3441.         glNormal3f(-0.3713906763541037f,0.0f,-0.9284766908852593f);
  3442.  
  3443.         glVertex3f(200.0f,80.0f,20.0f);
  3444.         glVertex3f(100.0f,40.0f,60.0f);
  3445.         glVertex3f(200.0f,112.0f,20.0f);
  3446.         glVertex3f(80.0f,120.0f,20.0f);
  3447.         glVertex3f(0.0f,40.0f,60.0f);
  3448.         glVertex3f(100.0f,40.0f,60.0f);
  3449.         glVertex3f(200.0f,80.0f,20.0f);
  3450.     glEnd();
  3451.  
  3452.     // Right Side Bottom
  3453.     
  3454.     glBegin(GL_POLYGON);
  3455.         //glNormal3f(0.0f,0.0f,1.0f);
  3456.         glNormal3f(-0.48507125007266594f,0.7276068751089989f,0.48507125007266594f);
  3457.                 
  3458.         glVertex3f(100.0f,0.0f,0.0f);
  3459.         glVertex3f(200.0f,80.0f,-20.0f);
  3460.         glVertex3f(100.0f,40.0f,-60.0f);
  3461.         glVertex3f(0.0f,40.0f,-60.0f);
  3462.         glVertex3f(100.0f,0.0f,0.0f);
  3463.     glEnd();
  3464.     
  3465.     // Right Side Top
  3466.  
  3467.     glBegin(GL_POLYGON);
  3468.         //glNormal3f(0.0f,0.0f,1.0f);
  3469.         //glNormal3f(-0.062347968638854966f,0.7793496079856871f,-0.6234796863885497f);
  3470.         glNormal3f(0.062347968638854966f,-0.7793496079856871f,0.6234796863885497f);
  3471.         
  3472.         glVertex3f(200.0f,80.0f,-20.0f);
  3473.         glVertex3f(100.0f,40.0f,-60.0f);
  3474.         glVertex3f(200.0f,112.0f,-20.0f);
  3475.         glVertex3f(80.0f,120.0f,-20.0f);
  3476.         glVertex3f(0.0f,40.0f,-60.0f);
  3477.         glVertex3f(100.0f,40.0f,-60.0f);
  3478.         glVertex3f(200.0f,80.0f,-20.0f);
  3479.     glEnd();
  3480.  
  3481. }
  3482.  
  3483. void drawEnemyWindshield()
  3484. {
  3485.     // Front Windshield
  3486.     setAmbientMaterialColor(0.3f,0.3f,0.6f,1.0f);
  3487.     setDiffuseMaterialColor(0.3f,0.3f,0.6f,1.0f);
  3488.     setSpecularMaterialColor(0.3f,0.3f,0.6f,1.0f);
  3489.     setMaterialShininess(100.0f);
  3490.     
  3491.     glPushMatrix();
  3492.         glTranslatef(-1.0f,0.0f,0.0f);
  3493.         
  3494.         glBegin(GL_POLYGON);
  3495.             //glNormal3f(0.0f,0.0f,1.0f);
  3496.             glNormal3f(0.7071067811865475f,-0.7071067811865475f,0.0f);
  3497.  
  3498.             glVertex3f(0.0f,40.0f,-40.0f);
  3499.             glVertex3f(80.0f,120.0f,-20.0f);
  3500.             glVertex3f(80.0f,120.0f,20.0f);
  3501.             glVertex3f(0.0f,40.0f,40.0f);
  3502.             glVertex3f(0.0f,40.0f,-40.0f);
  3503.         glEnd();
  3504.  
  3505.     glPopMatrix();
  3506. }
  3507. void drawEnemy()
  3508. {
  3509.     if (EnemyEngine[0].m_sleep==FALSE)
  3510.     {
  3511.         glPushMatrix();
  3512.             glScalef(0.1f,0.1f,0.1f);
  3513.             drawEnemyBody();
  3514.             drawEnemyWindshield();
  3515.         glPopMatrix();
  3516.     }
  3517. }
  3518. void Enemy_engine()
  3519. {
  3520.     checkEnemyCollision();
  3521.     moveEnemy();
  3522.  
  3523.     glTranslatef(EnemyEngine[0].x,EnemyEngine[0].y,EnemyEngine[0].z);
  3524.     glRotatef(dRadToDeg(EnemyEngine[0].m_angle_radians+((float)PI/2.0f))+90.0f, 0.0f, 1.0f, 0.0f);
  3525.  
  3526. }
  3527. void checkEnemyCollision()
  3528. {
  3529.     GLfloat distance;
  3530.     GLfloat x,y,z;
  3531.     int i;
  3532.     int index;
  3533.  
  3534.         for(i=0; i<MINE_LIST_SIZE; i++)
  3535.         {
  3536.             if(objMineList[i].m_active_flag==TRUE)
  3537.             {
  3538.  
  3539.                 x=EnemyEngine[0].x-objMineList[i].m_x;
  3540.                 y=EnemyEngine[0].y-objMineList[i].m_y;
  3541.                 z=EnemyEngine[0].z-objMineList[i].m_z;
  3542.  
  3543.                 distance=(GLfloat)sqrt(x*x+y*y+z*z);
  3544.  
  3545.                 if (distance<20)
  3546.                 {
  3547.                     objForce.m_hit++;
  3548.  
  3549.                     index=getAvailableExplosion();
  3550.                     if(index>-1)
  3551.                     {
  3552.                         objExplosion[index].x=x;
  3553.                         objExplosion[index].y=y;
  3554.                         objExplosion[index].z=z;
  3555.                         objExplosion[index].m_cpu_seconds=clock();
  3556.                         objExplosion[index].type=SPHERE_TYPE;
  3557.                     }
  3558.                 }
  3559.  
  3560.             }
  3561.         }
  3562.  
  3563. }
  3564.  
  3565. void moveEnemy()
  3566. {
  3567.  
  3568.     GLfloat x,z,x2,z2;
  3569.     GLfloat distance1,distance2,distance3;
  3570.     int direction;
  3571.     GLfloat angle;
  3572.     static long current_clicks=clock();
  3573.  
  3574.     if (EnemyEngine[0].m_sleep==TRUE)
  3575.     {
  3576.         if ((clock()-EnemyEngine[0].m_cpu_clicks)>10000)
  3577.         {
  3578.             EnemyEngine[0].m_sleep=FALSE;
  3579.         }
  3580.         return;
  3581.     }
  3582.  
  3583.     x=objForce.m_xPos;
  3584.     z=objForce.m_zPos;
  3585.  
  3586.     angle=EnemyEngine[0].m_angle_radians;
  3587.  
  3588.     //straight line displacement
  3589.     x2 = (GLfloat) (EnemyEngine[0].m_displacement*cos(angle)+EnemyEngine[0].x);
  3590.     z2 = (GLfloat) (-EnemyEngine[0].m_displacement*sin(angle)+EnemyEngine[0].z);
  3591.  
  3592.     distance1=(GLfloat) sqrt((x-x2)*(x-x2)+(z-z2)*(z-z2));
  3593.  
  3594.     //left of center displacement
  3595.     x2 = (GLfloat) (EnemyEngine[0].m_displacement*cos(angle+(1.57f/4.0f))+EnemyEngine[0].x);
  3596.     z2 = (GLfloat) (-EnemyEngine[0].m_displacement*sin(angle+(1.57f/4.0f))+EnemyEngine[0].z);
  3597.  
  3598.     distance2=(GLfloat) sqrt((x-x2)*(x-x2)+(z-z2)*(z-z2));
  3599.  
  3600.     //right of center displacement
  3601.     x2 = (GLfloat) (EnemyEngine[0].m_displacement*cos(angle-(1.57f/4.0f))+EnemyEngine[0].x);
  3602.     z2 = (GLfloat) (-EnemyEngine[0].m_displacement*sin(angle-(1.57f/4.0f))+EnemyEngine[0].z);
  3603.  
  3604.     distance3=(GLfloat) sqrt((x-x2)*(x-x2)+(z-z2)*(z-z2));
  3605.  
  3606.     if(distance1>90)
  3607.     {
  3608.  
  3609.         if (
  3610.             (distance2<distance1) &&
  3611.             (distance2<distance3)
  3612.             )
  3613.             
  3614.         {
  3615.             //right
  3616.             direction=RIGHT_DIRECTION;
  3617.             EnemyEngine[0].m_displacement=1.0f;
  3618.         }
  3619.         else if(
  3620.             (distance3<distance1) &&
  3621.             (distance3<distance2)
  3622.             )
  3623.         {
  3624.             //left
  3625.             direction=LEFT_DIRECTION;
  3626.             EnemyEngine[0].m_displacement=1.0f;
  3627.         }
  3628.         else
  3629.         {
  3630.             direction=FORWARD_DIRECTION;
  3631.             EnemyEngine[0].m_displacement=5.0f;
  3632.         }
  3633.         
  3634.         moveEnemyEngine(direction);
  3635.     }
  3636.     else
  3637.     {
  3638.         if((clock()-EnemyEngine[0].m_cpu_clicks)>(1000))
  3639.         {
  3640.             if (
  3641.                 (distance2<distance1) &&
  3642.                 (distance2<distance3)
  3643.                 )
  3644.                 
  3645.             {
  3646.                 //right
  3647.                 direction=RIGHT_DIRECTION;
  3648.                 EnemyEngine[0].m_displacement=0.1f;
  3649.             }
  3650.             else if(
  3651.                 (distance3<distance1) &&
  3652.                 (distance3<distance2)
  3653.                 )
  3654.             {
  3655.                 //left
  3656.                 direction=LEFT_DIRECTION;
  3657.                 EnemyEngine[0].m_displacement=0.1f;
  3658.             }
  3659.             else
  3660.             {
  3661.                 direction=FORWARD_DIRECTION;
  3662.                 EnemyEngine[0].m_displacement=0.2f;
  3663.                 //add levels later
  3664.                 if((clock()-current_clicks)>2000)
  3665.                 {
  3666.                     fireEnemyMissile();
  3667.                     current_clicks=clock();
  3668.                 }
  3669.             }
  3670.  
  3671.             
  3672.             moveEnemyEngine(direction);
  3673.  
  3674.             EnemyEngine[0].m_cpu_clicks=clock();
  3675.         
  3676.         }
  3677.     }
  3678.  
  3679.     
  3680.     if(EnemyEngine[0].x > GRID_SIZE)
  3681.         EnemyEngine[0].x = (GLfloat) GRID_SIZE;
  3682.  
  3683.     if(EnemyEngine[0].x < -GRID_SIZE)
  3684.         EnemyEngine[0].x = (GLfloat) -GRID_SIZE;
  3685.  
  3686.     
  3687.     if(EnemyEngine[0].z > GRID_SIZE)
  3688.        EnemyEngine[0].z = (GLfloat) GRID_SIZE;
  3689.  
  3690.     if(EnemyEngine[0].z < -GRID_SIZE)
  3691.        EnemyEngine[0].z = (GLfloat) -GRID_SIZE;
  3692.  
  3693. }
  3694. void moveEnemyEngine(int direction)
  3695. {
  3696.     GLfloat xDelta,zDelta;
  3697.  
  3698.         if(direction==RIGHT_DIRECTION)
  3699.         {
  3700.             EnemyEngine[0].m_angle_radians+=1.57f/8.0f;
  3701.         }
  3702.         else if(direction==LEFT_DIRECTION)
  3703.         {
  3704.             EnemyEngine[0].m_angle_radians-=1.57f/8.0f;
  3705.         }
  3706.  
  3707.  
  3708.         xDelta = (GLfloat) (EnemyEngine[0].m_displacement*cos(EnemyEngine[0].m_angle_radians));
  3709.         zDelta = (GLfloat) (-EnemyEngine[0].m_displacement*sin(EnemyEngine[0].m_angle_radians));
  3710.     
  3711.         EnemyEngine[0].x += xDelta;
  3712.         EnemyEngine[0].z += zDelta;
  3713.  
  3714. }
  3715.  
  3716.  
  3717. void drawExplosion()
  3718. {
  3719.     int i;
  3720.  
  3721.     for(i=0; i<EXPLOSION_SIZE; i++)
  3722.     {
  3723.         if(objExplosion[i].m_active_flag==TRUE)
  3724.         {
  3725.             if((clock()-objExplosion[i].m_cpu_seconds)>1000)
  3726.             {
  3727.                 objExplosion[i].m_available_flag=TRUE;
  3728.                 objExplosion[i].m_active_flag=FALSE;
  3729.                 objExplosion[i].scale_x=2.0f;
  3730.                 objExplosion[i].scale_y=2.0f;
  3731.                 objExplosion[i].scale_z=2.0f;
  3732.                 break;
  3733.             }
  3734.  
  3735.             glPushMatrix();
  3736.                 glTranslatef(objExplosion[i].x,objExplosion[i].y,objExplosion[i].z);
  3737.                 glScalef(objExplosion[i].scale_x,objExplosion[i].scale_y,objExplosion[i].scale_z);
  3738.                 objExplosion[i].scale_x+=1.0f;
  3739.                 objExplosion[i].scale_y+=1.0f;
  3740.                 objExplosion[i].scale_z+=1.0f;
  3741.                 glRotatef(90.0f,1.0f,0.0f,0.0f);
  3742.             
  3743.                 if (objExplosion[i].type==TORUS_TYPE)
  3744.                 {
  3745.                     setDiffuseMaterialColor(1.0f,0.0f,1.0f,0.6f);
  3746.                     torus(1.0f,3.0f);
  3747.                 }
  3748.                 else if(objExplosion[i].type==SPHERE_TYPE)
  3749.                 {
  3750.                     goldMaterial();
  3751.                     point_sphere(1.0f);
  3752.                 }
  3753.             glPopMatrix();
  3754.         }
  3755.         
  3756.     }
  3757. }
  3758. void fireEnemyMissile()
  3759. {
  3760.     GLint i;
  3761.  
  3762.     i=getAvailableEnemyMissile();
  3763.  
  3764.     if(i>-1)
  3765.     {
  3766.         enemyMissile[i].m_x=EnemyEngine[0].x;
  3767.         enemyMissile[i].m_y=EnemyEngine[0].y;
  3768.         enemyMissile[i].m_z=EnemyEngine[0].z;
  3769.         enemyMissile[i].m_Vo=10.0f;
  3770.         enemyMissile[i].m_angle_radians=EnemyEngine[0].m_angle_radians;
  3771.         enemyMissile[i].m_available_flag=FALSE;
  3772.         enemyMissile[i].m_active_flag=TRUE;
  3773.     }
  3774. }
  3775. int getAvailableEnemyMissile()
  3776. {
  3777.     int i;
  3778.     for(i=0; i<NUMBER_OF_MISSILES; i++)
  3779.     {
  3780.         if (enemyMissile[i].m_available_flag==TRUE)
  3781.         {
  3782.             return(i);
  3783.         }
  3784.     }
  3785.     return(-1);
  3786. }
  3787. void drawEnemyMissiles()
  3788. {
  3789.     GLint i=0;
  3790.     GLfloat x,z;
  3791.     GLfloat distance;
  3792.     GLint retVal;
  3793.  
  3794.     for(i=0; i<NUMBER_OF_MISSILES; i++)
  3795.     {
  3796.         if(enemyMissile[i].m_active_flag==TRUE)
  3797.         {
  3798.             x=(enemyMissile[i].m_Vo)*(float)cos(enemyMissile[i].m_angle_radians);
  3799.             z=-(enemyMissile[i].m_Vo)*(float)sin(enemyMissile[i].m_angle_radians);
  3800.  
  3801.             enemyMissile[i].m_x += x;
  3802.             enemyMissile[i].m_z += z;
  3803.  
  3804.             retVal=checkShipHit(enemyMissile[i].m_x,5.0f,enemyMissile[i].m_z);
  3805.  
  3806.             if (retVal==1)
  3807.             {
  3808.                 enemyMissile[i].m_available_flag=TRUE;
  3809.                 enemyMissile[i].m_active_flag=FALSE;
  3810.                 break;
  3811.             }
  3812.             else
  3813.             {
  3814.             
  3815.                 glPushMatrix();
  3816.                     glTranslatef(enemyMissile[i].m_x,enemyMissile[i].m_y,enemyMissile[i].m_z);
  3817.                     glScalef(0.5f,0.5f,0.5f);
  3818.  
  3819.                     glPushMatrix();
  3820.                         glRotatef(dRadToDeg(enemyMissile[i].m_angle_radians),0.0f,1.0f,0.0f);
  3821.                         glTranslatef(5.0f,10.0f,0.0f);
  3822.                         glRotatef(90.0f,0.0f,1.0f,0.0f);
  3823.                         toroidal_spiral();
  3824.                     glPopMatrix();
  3825.  
  3826.                 glPopMatrix();
  3827.             }
  3828.  
  3829.             x=EnemyEngine[0].x-enemyMissile[i].m_x;
  3830.             z=EnemyEngine[0].z-enemyMissile[i].m_z;
  3831.  
  3832.             distance=(float) sqrt(x*x+z*z);
  3833.             if (distance>100)
  3834.             {
  3835.                 enemyMissile[i].m_available_flag=TRUE;
  3836.                 enemyMissile[i].m_active_flag=FALSE;
  3837.             }
  3838.         }
  3839.     }
  3840.  
  3841.     if(EnemyEngine[0].m_hit==3)
  3842.     {
  3843.         EnemyEngine[0].m_hit=0;
  3844.         objForce.m_xPos=20.0f;
  3845.         objForce.m_zPos=-50.0f;
  3846.         objForce.m_angle_radians=-1.57f;
  3847.         mLives--;
  3848.     }
  3849.  
  3850. }
  3851. int checkShipHit(GLfloat x,GLfloat y,GLfloat z)
  3852. {
  3853. int retval;
  3854. GLfloat ship_x,ship_y,ship_z;
  3855. GLfloat vector_x,vector_y,vector_z;
  3856. GLfloat distance;
  3857. int index;
  3858.  
  3859.     retval=0;
  3860.  
  3861.     ship_x=objForce.m_xPos;
  3862.     ship_y=objForce.m_yPos;
  3863.     ship_z=objForce.m_zPos;
  3864.  
  3865.     vector_x=ship_x-x;
  3866.     vector_y=ship_y-y;
  3867.     vector_z=ship_z-z;
  3868.  
  3869.     distance=(GLfloat) sqrt(vector_x*vector_x+vector_y*vector_y+vector_z*vector_z);
  3870.  
  3871.     if(distance<=10)
  3872.     {
  3873.         EnemyEngine[0].m_hit++;
  3874.  
  3875.         index=getAvailableExplosion();
  3876.         if(index>-1)
  3877.         {
  3878.             objExplosion[index].x=x;
  3879.             objExplosion[index].y=y;
  3880.             objExplosion[index].z=z;
  3881.             objExplosion[index].m_cpu_seconds=clock();
  3882.             objExplosion[index].type=TORUS_TYPE;
  3883.         }
  3884.  
  3885.         //sound("hit.wav");
  3886.         retval=1;
  3887.  
  3888.         return(retval);
  3889.     }
  3890.  
  3891.     return(retval);
  3892. }
  3893.  
  3894. int checkEnemyHit(GLfloat x,GLfloat y,GLfloat z)
  3895. {
  3896. int retval;
  3897. GLfloat enemy_x,enemy_y,enemy_z;
  3898. GLfloat vector_x,vector_y,vector_z;
  3899. GLfloat distance;
  3900. int index;
  3901.  
  3902.     retval=0;
  3903.  
  3904.     enemy_x=EnemyEngine[0].x;
  3905.     enemy_y=EnemyEngine[0].y;
  3906.     enemy_z=EnemyEngine[0].z;
  3907.  
  3908.     vector_x=enemy_x-x;
  3909.     vector_y=enemy_y-y;
  3910.     vector_z=enemy_z-z;
  3911.  
  3912.     distance=(GLfloat) sqrt(vector_x*vector_x+vector_y*vector_y+vector_z*vector_z);
  3913.  
  3914.     if(distance<=10)
  3915.     {
  3916.         objForce.m_hit++;
  3917.  
  3918.         index=getAvailableExplosion();
  3919.         if(index>-1)
  3920.         {
  3921.             objExplosion[index].x=x;
  3922.             objExplosion[index].y=y;
  3923.             objExplosion[index].z=z;
  3924.             objExplosion[index].m_cpu_seconds=clock();
  3925.             objExplosion[index].type=TORUS_TYPE;
  3926.         }
  3927.  
  3928.  
  3929.         //sound("hit.wav");
  3930.         retval=1;
  3931.  
  3932.         return(retval);
  3933.     }
  3934.  
  3935.     return(retval);
  3936. }
  3937. void toroidal_spiral()
  3938. {
  3939.     GLfloat t;
  3940.     GLfloat x,y,z;
  3941.     GLfloat a,b,c,p,q;
  3942.     GLfloat theta;
  3943.  
  3944.     /*
  3945.     a=radius of the torus
  3946.     b=cross section radius of the torus
  3947.     p=number of interweavings
  3948.     q=number of twists
  3949.     c=constant
  3950.     */
  3951.         a=5.0f;
  3952.         b=3.0f;
  3953.         p=1.0f;
  3954.         q=7.0f;
  3955.         c=3.0f;
  3956.  
  3957.     glPushAttrib(GL_LIGHTING);
  3958.     glDisable(GL_LIGHTING);
  3959.     glRGB(255,0,0);
  3960.     glPushMatrix();
  3961.         glBegin(GL_LINE_STRIP);
  3962.         for(theta=0.0f; theta<=360.0f; theta+=1.0f)
  3963.         {
  3964.             t=(theta/180.0f*3.142f);
  3965.             x=(GLfloat)  ((a+b*cos(q*t))*cos(p*t));
  3966.             y=(GLfloat) ((a+b*cos(q*t))*sin(p*t));
  3967.             z=(GLfloat) (c*sin(q*t));
  3968.             glVertex3f(x,y,z);
  3969.         }
  3970.     glEnd();
  3971.     glPopMatrix();
  3972.     glPopAttrib();
  3973.     glEnable(GL_LIGHTING);
  3974.  
  3975. }
  3976. void drawMine()
  3977. {
  3978.     GLfloat glfMatColorRed[]={1.0f,0.1f,0.0f,1.0f};
  3979.     GLfloat glfMatColorYellow[]= {1.0f, 1.0f, 0.0f};
  3980.     GLfloat glfMatColorBlue[]={0.20f, 0.0f, 0.60f,1.0f};
  3981.     GLfloat glfMatColorWhite[]={0.8f, 0.8f, 0.80f,1.0f};
  3982.     GLfloat glfMatColorGrey[]={0.50f,0.50f,0.90f,1.0f};
  3983.     GLfloat glfMatColorGreen[]={0.0f, 0.6f, 0.1f,1.0f};
  3984.  
  3985.  
  3986.     glPushMatrix();
  3987.         glScalef(2.0f,2.0f,2.0f);
  3988.  
  3989.         glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,glfMatColorBlue);
  3990.  
  3991.         glBegin(GL_POLYGON);
  3992.             glNormal3f(0.0f,0.0f,1.0f);
  3993.             glVertex3f(  + 0.0f ,  + 4.0f ,  + 0.0f );
  3994.             glVertex3f(  -0.25f ,  + 2.0f ,  + 0.25f );
  3995.             glVertex3f(  + 0.25f ,  + 2.0f ,  + 0.25f );
  3996.         glEnd(); /*front of spike*/
  3997.     
  3998.         glBegin(GL_POLYGON);
  3999.             glNormal3f(0.0f,0.0f,-1.0f);
  4000.             glVertex3f(  + 0.25f ,  + 2.0f ,  -0.25f );
  4001.             glVertex3f(  -0.25f ,  + 2.0f ,  -0.25f );
  4002.             glVertex3f(  + 0.0f ,  + 4.0f ,  + 0.0f );
  4003.         glEnd();  /*back of spike*/
  4004.  
  4005.         glBegin(GL_POLYGON);
  4006.             glNormal3f(-1.0f,0.0f,0.0f);
  4007.             glVertex3f(  + 0.0f ,  + 4.0f ,  + 0.0f );
  4008.             glVertex3f(  -0.25f ,  + 2.0f ,  -0.25f );
  4009.             glVertex3f(  -0.25f ,  + 2.0f ,  + 0.25f );
  4010.         glEnd();  /*left of spike*/
  4011.  
  4012.         glBegin(GL_POLYGON);
  4013.             glNormal3f(1.0f,0.0f,0.0f);
  4014.             glVertex3f(  + 0.250f ,  + 2.0f ,  + 0.25f );
  4015.             glVertex3f(  + 0.25f ,  + 2.0f ,  -0.25f );
  4016.             glVertex3f(  + 0.0f ,  + 4.0f ,  + 0.0f );
  4017.         glEnd();  /*right of spike*/
  4018.  
  4019.  
  4020.         glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,glfMatColorRed);
  4021.  
  4022.         glBegin(GL_POLYGON);
  4023.             glNormal3f(0.0f,1.0f,0.0f);
  4024.             glVertex3f(  -0.50f ,  + 2.50f ,  -0.50f );
  4025.             glVertex3f(  -0.50f ,  + 2.50f ,  + 0.50f );
  4026.             glVertex3f(  + 0.50f ,  + 2.50f ,  + 0.50f );
  4027.             glVertex3f(  + 0.50f ,  + 2.50f ,  -0.50f );
  4028.         glEnd();      /*top of block*/
  4029.     
  4030.         glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,glfMatColorGrey);
  4031.  
  4032.         glBegin(GL_POLYGON);
  4033.             glNormal3f(0.0f,-1.0f,0.0f);
  4034.             glVertex3f(  -3.0f ,  + 0.0f ,  -3.0f );
  4035.             glVertex3f(  + 3.0f ,  + 0.0f ,  -3.0f );
  4036.             glVertex3f(  + 3.0f ,  + 0.0f ,  + 3.0f );
  4037.             glVertex3f(  -3.0f ,  + 0.0f ,  + 3.0f );
  4038.         glEnd();  /*bottom of big block*/
  4039.     
  4040.  
  4041.       
  4042.         glBegin(GL_POLYGON);
  4043.             glNormal3f(0.0f,1.0f,0.0f);
  4044.             glVertex3f(  -2.0f ,  + 2.00f ,  -2.0f );
  4045.             glVertex3f(  -2.0f ,  + 2.0f ,  + 2.0f );
  4046.             glVertex3f(  + 2.0f ,  + 2.0f ,  + 2.0f );
  4047.             glVertex3f(  + 2.0f ,  + 2.0f ,  -2.0f );
  4048.         glEnd();      /*top of big block*/
  4049.  
  4050.         glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,glfMatColorWhite);
  4051.     
  4052.         glBegin(GL_POLYGON);
  4053.             glNormal3f(0.0f,0.0f,1.0f);
  4054.             glVertex3f(  + 0.50f ,  + 3.0f ,  + 0.50f );
  4055.             glVertex3f(  - 0.50f ,  + 3.0f ,  + 0.50f );
  4056.             glVertex3f(  -1.0f ,  + 2.0f ,  + 1.0f );
  4057.             glVertex3f(  + 1.0f ,  + 2.0f ,  + 1.0f );
  4058.         glEnd(); /*front of block*/
  4059.     
  4060.         glBegin(GL_POLYGON);
  4061.             glNormal3f(0.0f,0.0f,-1.0f);
  4062.             glVertex3f(  + 0.5f ,  + 3.0f ,  -0.50f );
  4063.             glVertex3f(  + 1.0f ,  + 2.0f ,  -1.0f );
  4064.             glVertex3f(  -1.0f ,  + 2.0f ,  -1.0f );
  4065.             glVertex3f(  - 0.5f ,  + 3.0f ,  - 0.50f );
  4066.         glEnd();  /*back of block*/
  4067.  
  4068.         glBegin(GL_POLYGON);
  4069.             glNormal3f(-1.0f,0.0f,0.0f);
  4070.             glVertex3f(  -0.50f ,  + 3.0f ,  + 0.50f );
  4071.             glVertex3f(  - 0.50f ,  + 3.0f ,  - 0.50f );
  4072.             glVertex3f(  -1.0f ,  + 2.0f ,  -1.0f );
  4073.             glVertex3f(  -1.0f ,  + 2.0f ,  + 1.0f );
  4074.         glEnd();  /*left of block*/
  4075.  
  4076.         glBegin(GL_POLYGON);
  4077.             glNormal3f(1.0f,0.0f,0.0f);
  4078.             glVertex3f(  + 0.50f ,  + 3.0f ,  + 0.50f );
  4079.             glVertex3f(  + 1.0f ,  + 2.0f ,  + 1.0f );
  4080.             glVertex3f(  + 1.0f ,  + 2.0f ,  -1.0f );
  4081.             glVertex3f(  + 0.50f ,  + 3.0f ,  - 0.50f );
  4082.         glEnd();  /*right of block*/
  4083.             
  4084.             
  4085.             
  4086.         glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,glfMatColorWhite);        
  4087.  
  4088.         glBegin(GL_POLYGON);
  4089.             glNormal3f(0.0f,0.0f,1.0f);
  4090.             glVertex3f(  + 0.50f ,  + 2.0f ,  + 0.50f );
  4091.             glVertex3f(  - 0.50f ,  + 2.0f ,  + 0.50f );
  4092.             glVertex3f(  -0.50f ,  + 3.0f ,  + 0.50f );
  4093.             glVertex3f(  + 0.50f ,  + 3.0f ,  + 0.50f );
  4094.         glEnd(); /*front of inside of block*/
  4095.     
  4096.         glBegin(GL_POLYGON);
  4097.             glNormal3f(0.0f,0.0f,-1.0f);
  4098.             glVertex3f(  + 0.5f ,  + 2.0f ,  -0.50f );
  4099.             glVertex3f(  + 0.50f ,  + 3.0f ,  -0.50f );
  4100.             glVertex3f(  -0.50f ,  + 3.0f ,  -0.50f );
  4101.             glVertex3f(  - 0.5f ,  + 2.0f ,  - 0.50f );
  4102.         glEnd();  /*back of  inside of block*/
  4103.  
  4104.         glBegin(GL_POLYGON);
  4105.             glNormal3f(1.0f,0.0f,0.0f);
  4106.             glVertex3f(  -0.50f ,  + 2.0f ,  + 0.50f );
  4107.             glVertex3f(  -0.50f ,  + 2.0f ,  -0.50f );
  4108.             glVertex3f(  - 0.50f ,  + 3.0f ,  - 0.50f );
  4109.             glVertex3f(  -0.50f ,  + 3.0f ,  + 0.50f );
  4110.         glEnd();  /*left of  inside of block*/
  4111.  
  4112.         glBegin(GL_POLYGON);
  4113.             glNormal3f(1.0f,0.0f,0.0f);
  4114.             glVertex3f(  + 0.50f ,  + 3.0f ,  - 0.50f );
  4115.             glVertex3f(  + 0.50f ,  + 2.0f ,  - 0.50f );
  4116.             glVertex3f(  + 0.50f ,  + 2.0f ,  +0.50f );
  4117.             glVertex3f(  + 0.50f ,  + 3.0f ,  + 0.50f );
  4118.         glEnd();  /*right of  inside of block*/        
  4119.             
  4120.         glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,glfMatColorGrey);
  4121.  
  4122.         glBegin(GL_POLYGON);
  4123.             glNormal3f(0.0f,0.0f,1.0f);
  4124.             glVertex3f(  + 2.0f ,  + 2.0f ,  + 2.0f );
  4125.             glVertex3f(  - 2.0f ,  + 2.0f ,  + 2.0f );
  4126.             glVertex3f(  -3.0f ,  + 0.0f ,  + 3.0f );
  4127.             glVertex3f(  + 3.0f ,  + 0.0f ,  + 3.0f );
  4128.         glEnd(); /*front of big block*/
  4129.     
  4130.         glBegin(GL_POLYGON);
  4131.             glNormal3f(0.0f,0.0f,-1.0f);
  4132.             glVertex3f(  + 2.0f ,  + 2.0f ,  -2.0f );
  4133.             glVertex3f(  + 3.0f ,  + 0.0f ,  -3.0f );
  4134.             glVertex3f(  -3.0f ,  + 0.0f ,  -3.0f );
  4135.             glVertex3f(  - 2.0f ,  + 2.0f ,  - 2.00f );
  4136.         glEnd();  /*back of big block*/
  4137.  
  4138.         glBegin(GL_POLYGON);
  4139.             glNormal3f(-1.0f,0.0f,0.0f);
  4140.             glVertex3f(  -2.0f ,  + 2.0f ,  + 2.0f );
  4141.             glVertex3f(  - 2.0f ,  + 2.0f ,  - 2.0f );
  4142.             glVertex3f(  -3.0f ,  + 0.0f ,  -3.0f );
  4143.             glVertex3f(  -3.0f ,  + 0.0f ,  + 3.0f );
  4144.         glEnd();  /*left of big block*/
  4145.  
  4146.         glBegin(GL_POLYGON);
  4147.             glNormal3f(1.0f,0.0f,0.0f);
  4148.             glVertex3f(  + 2.0f ,  + 2.0f ,  + 2.0f );
  4149.             glVertex3f(  + 3.0f ,  + 0.0f ,  + 3.0f );
  4150.             glVertex3f(  + 3.0f ,  + 0.0f ,  -3.0f );
  4151.             glVertex3f(  + 2.0f ,  + 2.0f ,  - 2.0f );
  4152.         glEnd();  /*right of big block*/
  4153.         
  4154.     glPopMatrix();
  4155.  
  4156. }
  4157.  
  4158.